There are not 3 children the way that's written.
For now do not close any descriptors, leave them open. Exiting processes will close descriptors as needed. There is no purpose to closing descriptors, nor using dup(). Rather than be complicated, leave those things alone, so you can print out stuff and aid in your programming debug. I also recommend each time you print something you prepend any print statements similar to: "child1: pid(xxx) your comments" because all printf's will go to the standard console.
Use and touch pipe1 in child1 only. Do not touch any other pipes from withing child1
Same applies in sequence for pipe2/child2 and (not yet coded) pipe3/child3.
Remember that the child process is a copy of the parent at the time it was forked, thus it knows the about the relevant pipe. Still I would not bother closing irrelevant pipes, I'm the sort who feels that stuff gets cleaned up when you exit the process and also you try to do all that cleanup at the start and you may inadvertently close the incorrect resource, so for now don't do that.
Use waitpid() not wait. You can use W_NOHANG (validate my spelling there because I didn't look it up) and do so from within a loop where the exit conditions for the loop are that you've received exit signals from all children.
Why are you using pipes here? You're not doing anything with them. Yet? ...
|