diff --git a/SCR3.1/TP5/4 b/SCR3.1/TP5/4 new file mode 100644 index 0000000..2d7a9f7 --- /dev/null +++ b/SCR3.1/TP5/4 @@ -0,0 +1,4 @@ +total 12 + 571 drwx------ 2 root root 4096 Oct 5 16:41 snap-private-tmp +63266 drwx------ 3 root root 4096 Oct 5 16:41 systemd-private-751fc7fbe32349b8bb3b0cfa9273935a-systemd-logind.service-59VJA0 + 851 drwx------ 3 root root 4096 Oct 5 16:41 systemd-private-751fc7fbe32349b8bb3b0cfa9273935a-systemd-resolved.service-t8bMYr diff --git a/SCR3.1/TP5/5 b/SCR3.1/TP5/5 new file mode 100644 index 0000000..2d7a9f7 --- /dev/null +++ b/SCR3.1/TP5/5 @@ -0,0 +1,4 @@ +total 12 + 571 drwx------ 2 root root 4096 Oct 5 16:41 snap-private-tmp +63266 drwx------ 3 root root 4096 Oct 5 16:41 systemd-private-751fc7fbe32349b8bb3b0cfa9273935a-systemd-logind.service-59VJA0 + 851 drwx------ 3 root root 4096 Oct 5 16:41 systemd-private-751fc7fbe32349b8bb3b0cfa9273935a-systemd-resolved.service-t8bMYr diff --git a/SCR3.1/TP5/ex1.2.c b/SCR3.1/TP5/ex1.2.c new file mode 100644 index 0000000..397dec9 --- /dev/null +++ b/SCR3.1/TP5/ex1.2.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv){ + if (argc != 2){ + printf("Usage : %s ", argv[0]); + exit(EXIT_FAILURE); + } + pid_t p; + int pip, fd[2], outfile, d; + char buf; + pip = pipe(fd); + if (pip == -1){ + perror("Erreur lors de la création du pipe."); + exit(EXIT_FAILURE); + } + p = fork(); + outfile = open(argv[1], O_WRONLY|O_CREAT, 0644); + switch(p){ + case 0 : + close(fd[0]); + d = dup2(fd[1], 1); + execl("/usr/bin/ls", "ls", "-i", "-l", "/tmp", NULL); + close(fd[1]); + exit(0); + default : + close(fd[1]); + while(read(fd[0], &buf, sizeof(char)) > 0){ + write(outfile, &buf, sizeof(char)); + } + break; + case -1: + perror("Erreur lors de création d'un nouveau processus"); + exit(EXIT_FAILURE); + } + close(outfile); + return EXIT_SUCCESS; +} diff --git a/SCR3.1/TP5/ex1.3.c b/SCR3.1/TP5/ex1.3.c new file mode 100644 index 0000000..7530caa --- /dev/null +++ b/SCR3.1/TP5/ex1.3.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +int main(void){ + pid_t pr; + int fd[2], p; + char c; + p = pipe(fd); + if (p == -1){ + perror("Erreur de la création du tube"); + return EXIT_FAILURE; + } + pr = fork(); + switch(pr){ + case -1: + perror("Pas de nouveau processus, l'histoire s'arrête ici..."); + return EXIT_FAILURE; + case 0: + close(fd[0]); + dup2(fd[1], 1); + execl("/usr/bin/ls", "ls", ".", NULL); + exit(0); + default : + close(fd[1]); + dup2(fd[0], 0); + execl("/usr/bin/wc", "wc", "-l", NULL); + } + close(fd[0]); + return 0; +} diff --git a/SCR3.1/TP5/ex2.c b/SCR3.1/TP5/ex2.c deleted file mode 100644 index f65d7aa..0000000 --- a/SCR3.1/TP5/ex2.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int main(int argc, char** argv){ - if (args != 2){ - printf("Usage : %s ", argv[0]); - return EXIT_FAILURE; - } - int p[2], fd; - fd = open(argv[1], - pipe(p); - execl("/usr/bin/ls", "ls", "-i", "-l", "/tmp", NULL); - dup2(p[0],0); - diff --git a/SCR3.1/TP5/lol b/SCR3.1/TP5/lol new file mode 100644 index 0000000..e69de29 diff --git a/SCR3.1/TP5/t b/SCR3.1/TP5/t new file mode 100644 index 0000000..e69de29 diff --git a/SCR3.1/TP5/test b/SCR3.1/TP5/test new file mode 100644 index 0000000..e69de29