SCR/SCR3.1/TP5/ex1.3.c

34 lines
605 B
C
Raw Normal View History

2023-10-05 23:12:01 +02:00
#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;
}