> On Fri, 24 Sep 2004 10:34:50 -0500, Errin Larsen
<[EMAIL PROTECTED]> wrote:
> > On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky
<[EMAIL PROTECTED]> wrote:
> > > From: Errin Larsen <[EMAIL PROTECTED]>
> 
> <<SNIP>>
> 
> 
> > 
> > how do I wait() or waitpid() on more than one process?  don't both of
> > those make the wait()ing process sit still and do nothing else until
> > it gets a return?  I'll read perlipc again (man that's a hard one to
> > grok) and see what it says.
> > 
> > --Errin
> > 
> 
> Well, I found the following code snippet in perlipc:
> 
> sub REAPER {
>   my $child;
>   while( ( $child = waitpid( -1, WNOHANG ) ) > 0 ) {
>     $Kid_Status{$child} = $?;
>   }
>   $SIG{CHLD} = \&REAPER;
> }
> $SIG{CHLD} = \&REAPER;
> 
> This seems to do something similar to what I want, but I'm confused
> about exactly what it's doing.  what does the '-1' argument to
> waitpid() do?  What is the 'WNOHANG' flag?  Why are we reassigning
> '$SIG{CHLD}' to 'REAPER' inside of REAPER (this seems redundant to
> me!)
>

The -1 argument is to tell C<waitpid> that it should wait for any
processes in the session, aka all of your children as opposed to a
particular PID.  The C<WNOHANG> flag tells waitpid not to block if no
processes are available to reap, aka allow the parent to continue
processing something else.  The reassignment appears to be to avoid a
bug in older systems that use a SysV fork model, perldoc perlipc
includes a comment about this.

"Because Perl's signal mechanism is currently based on the signal(3)
function from the C library, you may sometimes be so misfortunate as to
run on systems where that function is "broken", that is, it behaves in
the old unreliable SysV way rather than the newer, more reasonable BSD
and POSIX fashion."

Followed by an example of a defensive signal handler.
 
> I realize this is getting away from the "beginner" focus of this
> mailing list, but I don't currently belong to any other mailing lists.
>  Thanks for any help you can throw at me.
> 
> --Errin
> 

I still suggest checking out the POE framework, specifically the
POE::Wheel::Run to handle all of this nonsense. At least once you are
satisfied that you understand the underpinnings.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to