嗨,有人可以解釋爲什麼我應該關閉我的管道後使用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/) –