Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Select on child output problem

by chromatic (Archbishop)
on May 03, 2012 at 02:09 UTC ( [id://968607]=note: print w/replies, xml ) Need Help??


in reply to Select on child output problem

What happens if you use eof on the current filehandle? You want to exhaust everything you can read without blocking, right? (You can control that the children always send a newline to terminate each line too.)

Something like this might get you further:

while (!eof( $fd )) { chomp( my $data = <$fd> ); if ($data) { push @results, [ split ":", $data ]; } else { # Other side (child) has closed connection. $file_iter->remove($_); close $fd; # Closing fd cleans up child } } sleep 10;

Replies are listed 'Best First'.
Re^2: Select on child output problem
by topher (Scribe) on May 03, 2012 at 02:31 UTC

    It looks like that leaves it blocking (and continuing to read) on the first filehandle it processes. I don't see it ever move on through the loop.

    From previous researching on this, it seems that there's no real equivalent to EOF for this type of communication without closing the file descriptor.

    Pulling all available data without blocking would be ideal, but my bigger problem is just getting to the next file handle from the group returned by IO::Select without waiting for a child to die first. I can't understand why it's trying to close and wait on the child PID. Even if I comment out the close bit (which isn't reached anyway), I still get the same result with the close on the FD and wait on the child PID.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://968607]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2024-04-23 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found