If I understand your code correctly, you first call pipe
in the shell process for every PIPE. You then proceed to fork
each process.
While you do close the unused end of each of the child's pipes in the child
process, this procedure suffers from two problems:
Every child has every pipe, and doesn't close the ones which don't belong to it
The parent (shell) process has all the pipes open.
Consequently, all the pipes are open, and the children don't get EOFs.
By the way, you need to wait()
for all the children, not just the last one. Consider the case where the first child does some long computation after closing stdout
, but remember that any computation or side-effect after stdout
is closed, even a short one, could be sequenced after the sink process terminates since multiprocessing is essentially non-deterministic.