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.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

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
    Thanks BrowserUK. The child processes are designed to always be non-blocking (or block with a timeout) and so will never hang. And, yes I was indeed looking for help with select. The select syntax is what confused me.
      will never hang.

      That's a brave assumption.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.