Ajout Exo4 TP5
This commit is contained in:
36
TP5/Exo1/exo1_3.c
Normal file
36
TP5/Exo1/exo1_3.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user