BUT2/SCR/controle/devoir39/cntr_r3.05/Ex1/gdf3.c

34 lines
694 B
C
Raw Permalink Normal View History

2023-10-23 13:23:36 +02:00
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
int i;
int x1, x2;
int ecrit, lu;
int p[2];
pipe(p);
for (i=0; i<3; i++){
x1 = fork();
if (i==0 && x1==0){
x2 = fork();
if (x2 == 0){
read(p[0],&lu,sizeof(int));
printf("%d received %d\n", getpid(), lu);
close(p[0]);
}
}
if (i==1 && x1==0){
x2 = fork();
if (x2==0){
ecrit = getpid();
write(p[1],&ecrit,sizeof(int));
close(p[1]);
}
}
}
return EXIT_SUCCESS;
}