Ajout Exo4 TP5

This commit is contained in:
2023-10-05 23:22:16 +02:00
parent eb6adbb2b5
commit 5276b50139
3 changed files with 125 additions and 1 deletions

36
TP5/Exo1/exo1_3.c Normal file
View 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;
}