49 lines
544 B
C
49 lines
544 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, sizeof(pid_t) );
|
|
|
|
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, sizeof(pid_t));
|
|
|
|
close (p[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
} |