[Melbourne-pm] $SIG{CHLD}

Scott Penrose scottp at dd.com.au
Sun May 4 05:11:04 PDT 2008


Daniel Pittman wrote:
> Scott Penrose <scottp at dd.com.au> writes:
>
>   
>> To capture exit values of forked daemons and not end up with a set of
>> zombie processes, we need to set $SIG{CHLD} to either 'ignore' or do
>> it fully. However once you do you loose the ability to capture the
>> return value of a 'system' call - unless you do it the hard way
>> (record in a hash the value by process id and then use that and remove
>> it after your system call).
>>
>> Anyway to get this all written down I wrote it on my site, but also as
>> partly an open question - is there a better way of doing 'system'
>> which does not depend on changes to $SIG{CHLD} or other solutions:
>>
>> http://scott.dd.com.au/wiki/SIG_CHLD
>>
>> So anyone know of one?
>>     
>
> Well, my very strong preference for doing /anything/ related to child
> processes is to use the IPC::Run module.  This wraps up a whole bunch of
> stuff from a dead simple 'run this' through to a complex 'write to and
> read from a filter, looking for specific out' and 'build a pipeline'
> stuff.
>
> The interface is sensible, light-weight, and the tool scales very well
> from start to finish.  
>
> It also, on investigation, handles $? appropriately internally so that
> it does the right stuff as far as I can tell.
>
> You may want to look into it, although it isn't always perfect:
>
> http://www.perlmonks.org/?node_id=674306
>
> Also, not always playing nice with SIG{CHLD} handlers, although this is
> very much in the "point gun at foot, pull trigger" style:
>
> http://www.depesz.com/index.php/2008/02/07/failing-ls/
>
> (Answer for those who don't want to read the code below the cut)
>
> Anyway, it should play nicely with existing SIG{CHLD} handlers that are
> written such that they don't break random library code and the like, and
> certainly beats hand-coding everything.
>
> Regards,
>         Daniel
>
> I have not actually tried the Perl co-process support, but everything
> else seems solid enough.
>
> 
>
> The answer is that the install SIG{CHLD} handler will wait for and
> collect the exit status from *everything*, which means that my the time
> the IPC::Run code in _cleanup (IPC/Run.pm:3157) is called the exit
> status is already gone as is the zombie process.
>   
THAT'S IT ! I knew I had seen a module around that I had used before, 
and I could not find it on CPAN, or remember it - sometimes getting the 
name right is tricky (better search for CPAN is another topic).

Have you ever spent a day writing a module that does not exist on CPAN, 
only to find at the end of that day you gained enough knowledge to find 
the module that did exist on CPAN :-)

Thanks

Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/melbourne-pm/attachments/20080504/cec68c11/attachment.html 


More information about the Melbourne-pm mailing list