Change 11987 by jhi@alpha on 2001/09/10 23:24:11

        Subject: avoiding hoardes of zombies
        From: Nicholas Clark <[EMAIL PROTECTED]>
        Date: Mon, 10 Sep 2001 22:00:40 +0100
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/pod/perlipc.pod#31 edit

Differences ...

==== //depot/perl/pod/perlipc.pod#31 (text) ====
Index: perl/pod/perlipc.pod
--- perl/pod/perlipc.pod.~1~    Mon Sep 10 17:30:06 2001
+++ perl/pod/perlipc.pod        Mon Sep 10 17:30:06 2001
@@ -121,11 +121,15 @@
     $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 @@
     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 @@
 
     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;
End of Patch.

Reply via email to