in reply to Forked pipe deadlock
Another approach could be having the children close the inherited output pipes. If you substitute your "children" code with:
if(!open($handles[$i], '|-')) { # child process for (my $j=0; $j<$i; $j++) { close($handles[$j]); } child(); exit 0; }
each child closes the pipes to its brothers before entering the child() sub. This allows the parent process to close the pipes in any order, because they are no longer blocked by other children.
This method works until you try to fork a new child after having closed one of the older pipes... I'm sure there should be a cleaner solution
Rule One: Do not act incautiously when confronting a little bald wrinkly smiling man.
|
|---|