Front page | perl.perl5.porters |
Postings from February 2007
Re: system() behavior with $SIG{CHLD} = IGNORE (was Re: [perl #36976])
Thread Previous
|
Thread Next
From:
Alan Ferrency
Date:
February 9, 2007 09:13
Subject:
Re: system() behavior with $SIG{CHLD} = IGNORE (was Re: [perl #36976])
Message ID:
Pine.BSF.4.58.0702091149110.25449@smx.pair.com
Hello,
> It looks like a lot of this discussion has been had before with
> bug #18849.
At the time I submitted that bug report, it was determined that Perl
was using SA_NOCLDWAIT when it should not be, on BSDish platforms.
(Really, it was my belief that SA_NOCLDWAIT should never have been used
by Perl, and that the only reason it was working on non-BSDish
platforms was because they didn't actually implement SA_NOCLDWAIT even
when Perl set it...)
> What behaviour do you get now with your C code in the bug db?
With the code on that bug report, I get:
fork 1: no one will wait for me.
fork 2
Parent: waiting for fork 2 to exit
fork 2 exiting
Fork 1 exiting
Parent done with fork 2.
fork 3
Parent: waiting for fork 3 to exit
Fork 3 exiting
Parent done with fork 3.
done
The interpretation: Even without SA_NOCLDWAIT, when the parent waits for
fork 2, it doesn't finish its wait4() until fork 1 has also exited. I
have verified this same behavior with other C and Perl tests, as well.
The change in behavior for FreeBSD is actually documented, much to my
dismay. Here is what it has to say about SA_NOCLDWAIT in FreeBSD 6.2's
`man sigaction`:
SA_NOCLDWAIT If this bit is set when calling sigaction() for the
SIGCHLD signal, the system will not create zombie
processes when children of the calling process
exit. If the calling process subsequently issues a
wait(2) (or equivalent), it blocks until all of the
calling process's child processes terminate, and
then returns a value of -1 with errno set to
ECHILD. The same effect of avoiding zombie cre-
ation can also be achieved by setting sa_handler
for SIGCHLD to SIG_IGN.
In FreeBSD 4, the last sentence was not present: SIGCHLD did not do the
same thing as SA_NOCLDWAIT; now it does.
I found the specific change in FreeBSD source which caused this change
in behavior for FreeBSD. Backing out this change and recompiling the
kernel gives me the behavior I expect:
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_exit.c.diff?r1=1.156&r2=1.157&f=h
I've also submitted a bug report, which has been ignored so far:
http://www.freebsd.org/cgi/query-pr.cgi?pr=108390
Only after I submitted the FreeBSD bug report did I notice that this new
behavior was documented. My interpretation of the silence on my FreeBSD
bug report, and documentation of the current behavior, is that the
FreeBSD folks consider this to be a feature, not a bug.
When we first saw this problem in FreeBSD 6, I immediately thought of
our old Perl bug patch, and dove straight into the Perl code looking for
SA_NOCLDWAIT problems. But the behavior change is not limited to Perl,
it's a FreeBSD change.
So, it's not Perl's "fault," but I still wonder whether Perl wants to
try to compensate for this particular BSDish quirk, specifically when
dealing with system() and backticks.
Thanks,
Alan Ferrency
pair Networks, Inc.
alan@pair.com
On Wed, 7 Feb 2007, Rick Delaney wrote:
> On Feb 06 2007, Alan Ferrency wrote:
> > Okay, what do you think of these alternate approaches:
> >
> > 1. "wait() works correctly; system() doesn't."
>
> Maybe. Or maybe $SIG{CHLD} = 'IGNORE' doesn't work. It looks like a
> lot of this discussion has been had before with bug #18849. Is it
> possible that the problem you are running into currently is related to
> this bug and Perl is not doing the right thing wrt SA_NOCLDWAIT on your
> failing platforms?
>
> What behaviour do you get now with your C code in the bug db?
>
> http://rt.perl.org/rt3/Public/Bug/Display.html?id=18849
>
> --
> Rick Delaney
> rick@bort.ca
>
Thread Previous
|
Thread Next