49 lines
520 B
C
49 lines
520 B
C
|
#include <unistd.h>
|
||
|
#include <stdio.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
|
||
|
int main(int argc, char const *argv[]){
|
||
|
|
||
|
int p[2];
|
||
|
pipe (p);
|
||
|
pid_t pid = getpid();
|
||
|
|
||
|
|
||
|
/*Pf1 -*/
|
||
|
if (fork() == 0) {
|
||
|
printf("processeur pf1\n");
|
||
|
|
||
|
/*pf1f1*/
|
||
|
if (fork() == 0) {
|
||
|
|
||
|
read(p[0], &pid, 1 );
|
||
|
|
||
|
while (1) {
|
||
|
sleep(3);
|
||
|
printf("PID : %ld\n", pid);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
close (p[0]);
|
||
|
|
||
|
}
|
||
|
|
||
|
/*Pf2 -> écrit*/
|
||
|
if (fork() == 0) {
|
||
|
|
||
|
//printf("while ok\n");
|
||
|
|
||
|
write (p[1], &pid, 1);
|
||
|
|
||
|
close (p[1]);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|