vsespb has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use POSIX; if (my $pid = fork) { sleep 1; alarm 10; kill (POSIX::SIGUSR2, $pid); $SIG{CHLD} = 'IGNORE'; while( wait() != -1 ){ print STDERR "wait\n"}; } else { $SIG{USR2} = sub { print "CHILD $$ EXIT\n"; exit(1); }; sleep 1 while (1); } print STDERR "DONE\n";
This code dies with ALARM, only on OpenBSD, only on Perl 5.12.x. (installed with perlbrew)
And it usually works well with openbsd vendor perl 5.12.2:
Locally applied patches: CVE-2010-0405 Updated CGI to 3.51 Updated Test::Simple to 0.98 Updated List::Util to 1.23 CVE-2011-1487 Updated Digest to 1.17 CVE-2011-2939 uncommitted-changes
Note that $SIG{CHLD} = 'IGNORE'; is a special perl feature to auto-reap zombies (i.e. it acts as calling wait() in signal handler), however replacing $SIG{CHLD} = 'IGNORE' with:
fixes problem$SIG{CHLD} = sub { while( wait() != -1 ){ print STDERR "wait0\n"}; };
I am wondering is this a bug or feature and mixing wait() in signal handlers and wait() in main code is bad idea?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SIG CHLD IGNORE and wait at same time
by rjt (Curate) on Aug 03, 2013 at 11:08 UTC | |
by vsespb (Chaplain) on Aug 03, 2013 at 18:03 UTC | |
by rjt (Curate) on Aug 04, 2013 at 03:47 UTC | |
by vsespb (Chaplain) on Aug 04, 2013 at 10:16 UTC | |
by rjt (Curate) on Aug 04, 2013 at 11:21 UTC |