【发布时间】:2015-03-17 05:48:26
【问题描述】:
我有一个使用fork() 创建多个子进程的程序。该程序在 parent.c 的 main 中启动。分叉后,父进程调用excel 执行child.c。我究竟如何在两个不同的程序之间共享管道。我知道我必须在 parent.c 中为每个子进程创建一个管道,如下所示:
int myPipe[nChildren][2];
int i;
for (i = 0; i < nChildren; i++) {
if (pipe(myPipe[i]) == -1) {
perror("pipe error\n");
exit(1);
}
close(pipe[i][0]); // parent does not need to read
}
但是我需要在 child.c 中做什么?
【问题讨论】: