Ex1 terminé

This commit is contained in:
Arnaud NGWALA NGWALA 2023-10-05 23:12:01 +02:00
parent b9fa8c4dce
commit 1e946adc0b
8 changed files with 83 additions and 15 deletions

4
SCR3.1/TP5/4 Normal file
View File

@ -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

4
SCR3.1/TP5/5 Normal file
View File

@ -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

42
SCR3.1/TP5/ex1.2.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char** argv){
if (argc != 2){
printf("Usage : %s <file>", 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;
}

33
SCR3.1/TP5/ex1.3.c Normal file
View File

@ -0,0 +1,33 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
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;
}

View File

@ -1,15 +0,0 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
if (args != 2){
printf("Usage : %s <file>", 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);

0
SCR3.1/TP5/lol Normal file
View File

0
SCR3.1/TP5/t Normal file
View File

0
SCR3.1/TP5/test Normal file
View File