我正在尝试创建一个创建多个子进程的进程,每个进程都调用该file()函数.
这是我到目前为止:
exec file.select相关管道(包含文件功能的输出)等待子进程的终止并从中读取.当我只使用一个子进程时,一切都运行良好:子进程终止管道中的所有输出,并且父进程读取它.但是,当我使用2个子进程时,它们不会终止; 文件功能进入"休眠"模式,等待更多输入.然后父母也被阻止,等待孩子们终止.
我已经创建了两个管道版本的最小包含示例:
#define NUM_CHILDREN (2)
//pipes from parent to children
int pipeP2C[NUM_CHILDREN][2];
//pipes from children to parent
int pipeC2P[NUM_CHILDREN][2];
int children_ids[NUM_CHILDREN];
int main()
{
//create pipes from parent to children and vice versa
for (int i = 0; i < NUM_CHILDREN; ++i){
pipe(pipeP2C[i]);
pipe(pipeC2P[i]);
}
//create first child
//Create initial g_parLevel child processes
pid_t pid;
int numForks = 0;
do
{
pid = fork();
// Parent process …Run Code Online (Sandbox Code Playgroud)