Phoenix.pm: SIG{CHLD} problems

Mike Cantrell mikec at autodispatch.com
Mon Jul 17 19:15:05 CDT 2000


----- Original Message -----
From: "Kevin Buettner" <kev at primenet.com>
To: <phoenix-pm-list at happyfunball.pm.org>
Sent: Monday, July 17, 2000 4:41 PM
Subject: Re: Phoenix.pm: SIG{CHLD} problems


<snip>

> I'm not sure what this is about, but are you sure you want to be catching
> SIGCHLD in the child process?  It seems to me that you might want to
> do
>
>     $SIG{CHLD} = 'DEFAULT';
>

The signal handler was installed in the parent (sorry, my email was a little
confusing). None of the children should exit (they're on a continuous loop
reading data from a socket) and if they do exit, I want to start cleaning
stuff up, write to the error log, and exit. The problem is that the glob
keeps throwing me false positives.


> > I know that sysetm(), backticks, etc cause forks but they should be
> > checking for their own children.  Could it be possible that glob()
> > forks but doesn't clean up after itself?  Has anyone else had
> > similar problems?
>
> I'm sure glob does clean up after itself when $SIG{CHLD} is set to the
> default handler.  I too find it a bit surprising that you're seeing the
> SIGCHLD signals from system, glob, etc... but after thinking about it
> for a moment or two, it's not *that* surprising.
>
> When one calls waitpid() in C, you don't know in advance what it will
> return; i.e, it could return you the pid of the child that you're
> expecting to see or some other child that you started up a while ago
> and didn't expect to see exiting at this point.  In other words,
> there's no way for Perl's system(), et al. to call waitpid() only on
> the processes that they fork off.
>
> > Here's the assigned routine to $SIG{CHLD}: (yep, straight outta the
cookbook)
> >
<snip>

> You might wish to modify this a little bit so that you keep track of
> the pids of the child processes that you explicitly fork off.  Then, in
> your REAPER sub, you can check to see if it's one that you started and
> if so check the exit code...


Yeah, that's what I ended up doing and it worked well except that  I still
got those annoying messages to STDERR but it was non-critical at that point.

One interesting thing that I *just* tried was running the code on a box with
perl 5.6 and the problem disappeared so maybe there is a problem w/ older
versions of glob (5.005_03 is what the problem box is using).




More information about the Phoenix-pm mailing list