Front page | perl.perl5.porters |
Postings from September 2013
Re: [perl #74854] wait and waitpid can return -1 even when there arerunning child forks.
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
September 20, 2013 08:52
Subject:
Re: [perl #74854] wait and waitpid can return -1 even when there arerunning child forks.
Message ID:
20130920085143.GI66035@plum.flirble.org
On Fri, Sep 20, 2013 at 12:03:01AM -0600, Charlie Strauss wrote:
> Blast from the past! Could you send me back my script and I'll test it if I can. I don't have that version of ubuntu or osx any longer.
The ticket is online at
http://rt.perl.org/rt3/Ticket/Display.html?id=74854
I've appended your script. I can't get it to print "Perl bug detected!!" with
v5.8.9 (the version in your report) on either OS X 10.6 (one later than you
had) or
Linux gcc20 2.6.32-5-amd64 #1 SMP Mon Jan 16 16:22:28 UTC 2012 x86_64 GNU/Linux
I had hoped that I could get it to, so that I could bisect to find what fixed
the problem.
Nicholas Clark
#!/usr/bin/perl -w
use strict;
my @command1 = ("sleep 360");
my @command2 = ("sleep 2");
my $pid1 = fork();
unless ($pid1) {
exec @command1;
};
my $pid2 = fork();
unless ($pid2) {
exec @command2;
};
# THIS IS WHAT TRIGGERS THE BUG
$SIG{CONT} = sub{ my $sig = $_[0]; kill $sig, $pid2; warn " dead process $pid2 was sent $sig\n"};
# NEITHER OF THESE WILL TRIGGER THE BUG. thus the bug is due to sending a sigCONT to the dead process.
#$SIG{CONT} = sub{ my $sig = $_[0]; kill $sig, $pid1; warn "live process $pid1 was sent $sig\n"};
#$SIG{CONT} = sub{ my $sig = $_[0]; warn "did nothing with $sig\n"};
warn "processes running:\n";
warn `ps au | grep $pid2 | grep -v grep` ;
warn `ps au | grep $pid1 | grep -v grep` ;
wait(); # reap process #2
warn "\n\ncommand @command2 should have been reaped now\n";
warn "\nprocesses running:\n";
my $r = `ps au | grep $pid2 | grep -v grep` ;
warn $r if $r;
warn `ps au | grep $pid1 | grep -v grep` ;
warn "\n\nHUMAN SLAVE: To induce the bug, pull up another terminal and type:
kill -CONT $$
then
kill -CONT $$
then
kill -CONT $$
then
kill -CONT $$
then
kill -QUIT $pid1
(NOTICE the last one was $pid1 and not $$)\n";
warn "\n\nParent will first use wait()\n";
if ( wait() == -1 ) {warn "perl thinks the child process ended, but did it?\n";};
if ( kill 0,$pid1) {
warn "\nPerl bug detected!! the process $pid1 is still running!!\n";
warn "you can see this because waitpid is now zero:", waitpid(-1,1),"\n";
warn "and you can also see it in the process list as active:";
warn `ps au | grep $pid1 | grep -v grep`;
}
warn "\n\nParent will next use waitpid()\n";
if ( waitpid(-1,0) == -1 ) {warn "perl thinks the child process ended, but did it?\n";};
if ( kill 0,$pid1) {
warn "\nPerl bug detected!! the process $pid1 is still running!!\n";
warn "you can see this because waitpid is now zero:", waitpid(-1,1),"\n";
warn "and you can also see it in the process list as active:";
warn `ps au | grep $pid1 | grep -v grep`;
}
# here is the only way I know of to work around this bug:
warn "\n\nParent is working around wait() bug by trapping it in a double waitpid wrapper\n";
while ( waitpid(-1,1) > -1 ) { wait(); warn "perl wait() thinks the child process ended, but we trapped this bug\n";};
if ( kill 0,$pid1) {
warn "\nPerl bug detected!! the process $pid1 is still running!!\n";
warn "you can see this because waitpid is now zero:", waitpid(-1,1),"\n";
warn "and you can also see it in the process list as active:";
warn `ps au | grep $pid1 | grep -v grep`;
}
else {
warn "\n\nThis time the process $pid1 really is ended for real!!!!\n";
warn "you can see this because waitpid is now -1:", waitpid(-1,1),"\n";
warn "and you can also see it is NOT in the process list:";
warn `ps au | grep $pid1 | grep -v grep`;
}
Thread Previous
|
Thread Next