r305_dm/TP5/Exo1/exo1_3.c
2023-10-05 23:22:16 +02:00

36 lines
605 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>
int main(void)
{
int fd[2], p;
char c;
p = pipe(fd);
assert(p != -1);
pid_t pr = fork();
assert(pr != -1);
switch (pr)
{
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;
}