<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Daniel Pittman wrote:
<blockquote cite="mid:87iqxuqxyd.fsf@rimspace.net" type="cite">
  <pre wrap="">Scott Penrose <a class="moz-txt-link-rfc2396E" href="mailto:scottp@dd.com.au">&lt;scottp@dd.com.au&gt;</a> writes:

  </pre>
  <blockquote type="cite">
    <pre wrap="">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:

<a class="moz-txt-link-freetext" href="http://scott.dd.com.au/wiki/SIG_CHLD">http://scott.dd.com.au/wiki/SIG_CHLD</a>

So anyone know of one?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
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:

<a class="moz-txt-link-freetext" href="http://www.perlmonks.org/?node_id=674306">http://www.perlmonks.org/?node_id=674306</a>

Also, not always playing nice with SIG{CHLD} handlers, although this is
very much in the "point gun at foot, pull trigger" style:

<a class="moz-txt-link-freetext" href="http://www.depesz.com/index.php/2008/02/07/failing-ls/">http://www.depesz.com/index.php/2008/02/07/failing-ls/</a>

(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.
  </pre>
</blockquote>
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).<br>
<br>
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 :-)<br>
<br>
Thanks<br>
<br>
Scott<br>
</body>
</html>