summaryrefslogtreecommitdiff
path: root/pod/perlipc.pod
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2001-09-10 23:00:40 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2001-09-10 23:24:11 +0000
commit816229cf4a3690b9abc75d05aaabf5930497cf24 (patch)
treea60f04709ccdcb27604bc22d8dfff362ecf0a313 /pod/perlipc.pod
parente83d50c9254af4011034b5ec3368b06bb6254055 (diff)
downloadperl-816229cf4a3690b9abc75d05aaabf5930497cf24.tar.gz
avoiding hoardes of zombies
Message-ID: <20010910220040.C1512@plum.flirble.org> p4raw-id: //depot/perl@11987
Diffstat (limited to 'pod/perlipc.pod')
-rw-r--r--pod/perlipc.pod20
1 files changed, 15 insertions, 5 deletions
diff --git a/pod/perlipc.pod b/pod/perlipc.pod
index a1df3e42e0..56816b15d6 100644
--- a/pod/perlipc.pod
+++ b/pod/perlipc.pod
@@ -121,11 +121,15 @@ signal handlers like this:
$SIG{CHLD} = \&REAPER;
# now do something that forks...
-or even the more elaborate:
+or better still:
use POSIX ":sys_wait_h";
sub REAPER {
my $child;
+ # If a second child dies while in the signal handler caused by the
+ # first death, we won't get another signal. So must loop here else
+ # we will leave the unreaped child as a zombie. And the next time
+ # two children die we get another zombie. And so on.
while (($child = waitpid(-1,WNOHANG)) > 0) {
$Kid_Status{$child} = $?;
}
@@ -724,10 +728,13 @@ go back to service a new client.
my $waitedpid = 0;
my $paddr;
+ use POSIX ":sys_wait_h";
sub REAPER {
- $waitedpid = wait;
+ my $child;
+ while (($waitedpid = waitpid(-1,WNOHANG)) > 0) {
+ logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
+ }
$SIG{CHLD} = \&REAPER; # loathe sysV
- logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
$SIG{CHLD} = \&REAPER;
@@ -881,10 +888,13 @@ to be on the localhost, and thus everything works right.
my $waitedpid;
+ use POSIX ":sys_wait_h";
sub REAPER {
- $waitedpid = wait;
+ my $child;
+ while (($waitedpid = waitpid(-1,WNOHANG)) > 0) {
+ logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
+ }
$SIG{CHLD} = \&REAPER; # loathe sysV
- logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
$SIG{CHLD} = \&REAPER;