|P is for Practical|
Select on child output problemby topher (Scribe)
|on May 03, 2012 at 01:13 UTC||Need Help??|
topher has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to have a process start a couple of child processes, and then continually watch the output from the child processes to monitor status. However, when I try looping through the filehandles associated with the child processes (using IO::Select), the parent reads from the first child, and then seems to (internally) close() the filehandle and waitpid() on the child PID.
I feel like I'm probably missing something small or I have an error I'm not seeing here, but I'm running out of ideas. Here's a stripped down piece of code that shows what I'm seeing:
And here's what's happening "under the hood" with the parent process when I run it:
You can see the select, followed by the read. That part works fine. You can also see the sleep call that I put at the end of the loop as a marker. However, as soon as it finishes the sleep and hits the end of the for loop, it closes the filehandle and wait()'s for the child PID to end. I'm just not sure why, or how to fix this.
If there's an overall better way of doing this, I'd love to hear it. However, I'd still like to figure this out so I understand why it's happening.
UPDATE: I think I figured it out. At the least, I've got things working now. For details, see my response below: Re: Select on child output problem