1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
int main(){
int pid ;
double i = 20.0;
double j = 19.0;
double k = 5.0;
double total = 0;
int t1[2];int t2[2];/*future tube */
pipe(t2);/* création des tubes*/
pipe(t1);
pid = fork();
if(pid == 0){/* ds le 1er fils*/
double value ;
close(t1[1]);
read(t1[0],&value,sizeof(double));
close(t1[0]);
total = value + 5;
printf("%f \n",total);
write(t2[1],&total,sizeof(total));
/*elle écrit dans le 2éme tube*/
close(t2[1]);
exit(0);
}
else{/* ds le pére */
write(t1[1],&i,sizeof(i));
pid = fork();
if(pid == 0){/*pére*/
printf("%f \n",total);
read(t1[0],&total,sizeof(double));
printf("%f \n",total);
}else{
double value ;
read(t2[0],&value,sizeof(double));
total = value * 2 ;
printf("%f \n",total);
write(t1[1],&total,sizeof(double));
}
}
} |
Partager