pipe(fd1);
pipe(fd2);
pid_t pId = fork();
if(pId < 0 )
{
printf("fork() failed\n");
exit(-1);
}
if(pId == 0)
{
close(fd1[1]);
read(fd1[0], &num, sizeof(var));
printf("Value: %d\n", num);
int i;
for(i=num-1; i> 0; i--) {
num = num*i;
}
close(fd2[0]);
write(fd2[1], &num, sizeof(num));
_exit(EXIT_SUCCESS);
}
else
{
close(fd1[0]);
write(fd1[1], &var, sizeof(var));
close(fd2[1]);
read(fd2[0], &f, sizeof(num));
printf("Factorial: %d \n", f);
}
以上代码是两个相关过程之间的两个通信的示例。谁能帮助我理解流程之间传递的消息的基本流程。