Add 'ASR3.1/TP06 Redirection tubes '

This commit is contained in:
lefevres 2021-12-06 17:35:53 +01:00
parent 2b2cc8ccd6
commit 31c93c3068

View File

@ -0,0 +1,49 @@
#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;
}