在操作系统概念(Avi Silberschatz,第9版)的第145页上,它指出
请注意,普通管道需要UNIX和Windows系统上的通信进程之间的父子关系。这个 意味着这些管道只能用于之间的通信 在同一台机器上进行处理。
但是,当我在linux机器上执行命令ps -el | grep 0
时,ps和grep两个进程都将bash作为其父进程。其他资源确认壳管是单向的普通管道。如果需要父子关系,为什么ps和grep进程是bash下的兄弟姐妹?只是为了证实我对管道的理解,教科书中的陈述是错误的还是我在这里误解了什么?
答案 0 :(得分:1)
The statement is true, but must be interpreted mixing with descriptor inheritance. What it means is that to setup a piping you need a parent-child relationship, not that communication with pipe is only possible between parent and children. So in your case, bash creates the pipe and transmit it to both children ps and grep (one writing in it while the other reads). Thus, both children communicates with the a pipe created by their parent.