Price, Jason wrote: > Bob, > > Thanks for the input - it's quite helpful. However, I don't fully > understand some of the code - maybe you could help clear it up for > me. The parts I'm unclear on are: >
Wolf's aready explained most everything. I'll throw in a bit more... > - the usage of "pipe READER, WRITER", and then the subsequent > references to READER and WRITER. pipe() creates a pair of handles that are connected. Anything written to WRITER can be read from READER. After the fork, both parent and child have a copy of each handle. So, the child can talk back to the parent by writing data to WRITER. Since all the children get a copy of WRITER, they are all writing to the same pipe. That way, the parent can read the data from all the children on READER. You might wonder if data from the multiple writers might be intermingled. As long as any child writes less than PIPE_BUF characters (a system-specific limit, which POSIX requires to be at least 512 bytes IIRC), the writes will be atomic. > - the usage of $| It's important to flush each write to the pipe to avoid the intermingling. > - "1 while wait() > 0" That just reaps the exit statuses to prevent zombies; the children have already exited (otherwise the loop wouldn't have exited.) You might want the exit statuses or not. You can also usually use $SIG{CHLD} = 'IGNORE' prior to the forking loop if you don't care about exit statuses. see "perldoc perlipc" > > Hmm...I guess that's the majority of the script. :) I can follow > what it does, but I'm not entirely sure why it does it. > > Also, is there any way I can self-contain the output from each child > process? You can use a separate pipe for each child, but now you have the problem of reading from multiple handles, which requires using select() or some such. I go with Wolf's recommendation of having the child pass back his identity with each message. You can use the identity to split the output back into arrays or whatever. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>