34 lines
694 B
C
34 lines
694 B
C
|
#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;
|
||
|
}
|