SCR/SCR3.1/devoir27/ex1/gdf3.c
2023-12-10 15:48:26 +01:00

39 lines
577 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#define BUF_SIZE 128
int main(void){
pid_t x, x1, x2, x3;
int p[2];
char buf;
assert(pipe(p) != -1);
x1 = fork();
if (x1 == 0){
x2=fork();
if (x2 == 0){
x = fork();
if (x == 0){
close(p[0]);
dup2(p[1], 1);
close(p[1]);
printf("%d", getpid());
}
x3=fork();
}
sleep(1);
}
if (x1 > 0){
close(p[1]);
while(read(p[0], &buf, sizeof(char)) > 0)
write(1, &buf, sizeof(char));
}
close(p[0]);
printf("\n");
return EXIT_SUCCESS;
}