in reply to Reading from Many Child Processes using Pipes
I know there are a few (unrelated to the problem) issues in the code, but in the interest of getting a working solution
The major problem is that if one of your kids fails to write because its hung; then your entire sets of processes will block.
The parent will block at the readline the first time it tries to read from the blocked child; and all the other children will block once they've written a buffer full of output to their pipe that the parent is no longer reading from.
while (1) { foreach my $i (0..$#kids) { if (<$readers[$i]>) {
The solution is to use select which will prevent you from trying to read from a kid that hasn't written something for you to read.
There are lots of select loop examples on perlmonks to get you started.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading from Many Child Processes using Pipes
by sved (Novice) on Oct 31, 2015 at 18:39 UTC | |
by BrowserUk (Patriarch) on Oct 31, 2015 at 20:18 UTC |