36 lines
709 B
C
36 lines
709 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <sys/wait.h>
|
||
|
|
||
|
int main() {
|
||
|
int ecrit;
|
||
|
int lu;
|
||
|
int p[2];
|
||
|
|
||
|
pipe(p);
|
||
|
pid_t pf = fork();
|
||
|
|
||
|
if (pf == 0) {
|
||
|
pid_t pf1 = fork();
|
||
|
if (pf1 == 0) {
|
||
|
while (read(p[0],&lu,sizeof(int)) > 0){
|
||
|
printf("%d received %d\n", getpid(), lu);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
pid_t pf2 = fork();
|
||
|
if (pf2 == 0) {
|
||
|
}
|
||
|
else{
|
||
|
while(1){
|
||
|
sleep(3);
|
||
|
ecrit = getpid();
|
||
|
printf("%d sent %d\n", ecrit, ecrit);
|
||
|
write(p[1],&ecrit,sizeof(int));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|