嗨,有人可以解释为什么我应该关闭我的管道后使用execlp?为什么我关闭管道后关闭execlp?
下面是一个例子:
if(cid == 0)
{//Only child cid can run this code
char msg[256];
//Redirect output into the pipe instead of the terminal
dup2(pipe1Fds[1],STDOUT_FILENO);
//Close pipes or the pipe reader will not get an EOF
close(pipe1Fds[0]);
close(pipe1Fds[1]);
close(pipe2Fds[0]);
close(pipe2Fds[1]);
//Execute cmd1
execlp(cmd1,cmd1,(char *)0);
exit(0);
}
阅读[高级Linux编程](http://advancedlinuxprogramming.com/) –