【发布时间】:2015-07-02 08:32:17
【问题描述】:
我有一根烟斗。
int anotherPipe[2];
make(anotherPipe);
以下两个进程都可以访问此管道。
流程A:
close(anotherPipe[0]);
dup2(anotherPipe[1], 1); //redirect stdout to pipe
execl("/usr/bin/who", "usr/bin/who", NULL);
close(anotherPipe[1]); //this is never executed
流程 B:
close(anotherPipe[1]);
read(anotherPipe[0], stringbuffer, bytestoread);
printf("%s\n", buffer);
printf("checkpoint\n");
close(anotherPipe[0]);
execl 的“who”命令的输出通过管道重定向到进程 B,并在此打印。但是现在我的进程 B 没有终止,尽管检查点已打印。
“不终止”是指终端中不显示以下内容:
myusername@ubuntucomputer:~$
这里发生了什么以及如何解决?
编辑:解决了非终止进程 B 的问题。它终止了,但我的顶级进程在 A 和 B 之前完成,所以
myusername@ubuntucomputer:~$
印得早了很多。我使用了 waitpid(),现在一切正常。
【问题讨论】:
-
你能把整个源码发出来吗