develooper Front page | perl.perl5.porters | Postings from March 2003

SIGCHLD and zombies issue

From:
Stas Bekman
Date:
March 8, 2003 05:25
Subject:
SIGCHLD and zombies issue
Message ID:
3E69EED8.3080702@stason.org
One of the readers of the mod_perl guide was trying to suggest why a 
localization of:

   $SIG{CHLD} = 'IGNORE';

doesn't work. His suggestion of local() overriding the magic wasn't quite 
right, because it does work for other SIGnals. However things don't look quite 
right across quite a few perl versions, so it'd be nice to clear out this issue.

First of all, the following standalone script creates a zombie child process, 
contrary to what perlipc.pod says (tested with perl-5.005-03 .. perl-blead):

---
$SIG{CHLD} = 'IGNORE';

defined (my $kid = fork) or die "Cannot fork: $!\n";
if ($kid) {
     # no wait()/waitpid() on purpose!
     print "Parent has finished\n";
} else {
     # do something time-consuming
     CORE::exit(0);
}

sleep 100; # zombie quits when sleep ends
---

$SIG{CHLD} = 'IGNORE'; doesn't take any effect. If you look in another 
console, on the list of processes you will see a <defunc> child process. This 
is at least how it looks on my machine (linux/2.4.19).

However the same script running under mod_perl does work. Meaning that 
whatever C layer should be affected by setting $SIG{CHLD} is not affected by 
Perl, while does affected by Apache C guts.

Now if you try to localize the setting under mod_perl, it breaks as well (we 
get a zombie)

Now I'm looking for input on different other ways to avoid zombies, this is 
covered in details here:
http://perl.apache.org/docs/1.0/guide/performance.html#Avoiding_Zombie_Processes

What I want to solve is:

1) why $SIG{CHLD} = 'IGNORE'; takes no effect in the plain perl script
2) why local $SIG{CHLD} = 'IGNORE'; doesn't behave quite the same as 
non-localized version

Also I doubt that this has anything to do with 5.8.0's deferred signals, since 
the problem is not different in earlier perls.

Thank you.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About