如果我有,我想管4个过程:我是否必须为C中的每对进程创建一个新管道?
process1 | process2 | process3 | process4
做我必须做3米个人的管道喜欢这个
int pipe1[2];
int pipe2[2];
int pipe3[2];
或可我莫名其妙地回收管道的名字,像在这个伪代码:
int pipe1[2]; // we use ONLY two pipe names: pipe1
int pipe2[2]; // and pipe2
pipe(pipe1); // getting 2 file descriptors here
pipe(pipe2); // and 2 here
for process=1 to 4
if (process==3) // getting 2 new file descriptors for
pipe(pipe1); // process3|process4 (reusing pipe1)
fork() // forking here
if (child 1) then
use pipe1
if (child 2) then
use pipe1
use pipe2
if (child 3) then
use pipe2
use pipe1 //the pipe1 that we re-pipe()ed
if (child 3) then
use pipe1 //the pipe1 that we re-pipe()ed
这项工作?我不知道repipe1 pipe1是否会对使用pipe1的以前的分叉进程产生影响。