【发布时间】:2013-09-24 01:55:02
【问题描述】:
以下是generalpipe()用法示例:
int fd[2];
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
exit(1);
}
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
////.....some code....////
exit(0);
}
else
{
/* Parent process closes up output side of pipe */
close(fd[1]);
////.....some code....////
}
我想知道的是是否调用子进程中的close(fd[0])和父进程中的close(fd[1])是必要的。
如果我不使用会发生什么 close() 他们只在子级中使用 fd[1] 而在父级中使用 fd[0]。
它是否关闭只是为了让我们不小心对这些描述符做某事?
【问题讨论】: