【发布时间】:2020-08-01 20:24:21
【问题描述】:
是否可以使用一个管道在进程之间进行读写?我的伪代码很像下面。我试过了,但它给了我一个错误,说“错误的文件描述符”。
create fd[2]
create pipe(fd)
parent:
close fd[0]
write something to fd[1]
close fd[1]
// wait for child's signal
close fd[1]
read the response fd[0]
close fd[0]
child:
close fd[1]
read the pipe fd[0]
close fd[0]
// write an answer to the parent via the existing pipe
// no need to close fd[0], since it's already closed
write the answer fd[1]
close fd[1]
signal to the parent
非常感谢。
【问题讨论】: