I\'ve seen this question before, but still a bit confused: how would I create communication between child processes of the same parent? All I\'m trying to do at the moment i
You don't need to create the processes first. The solution is as follows: you first create all the needed pipes, save them in some array. Then you do a fork
, redirect input and output streams (for the child process) accordingly, close unused pipe ends and perform an exec
. Pipes can exist without the corresponding processes, they have buffers, so you can write to a pipe while nobody's still reading, it will be ok.
You should just be aware of closing unused id's before doing exec
. And be careful writing to a pipe which input endpoints (all the input endpoints) could become closed: it could result in a SIGPIPE
.