This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handle multiple children exiting in perlipc example
authorTony Cook <tony@develop-help.com>
Fri, 12 Jul 2013 07:12:46 +0000 (17:12 +1000)
committerTony Cook <tony@develop-help.com>
Fri, 19 Jul 2013 02:03:43 +0000 (12:03 +1000)
pod/perlipc.pod

index 69567e9..decb59b 100644 (file)
@@ -124,11 +124,10 @@ example:
     $SIG{CHLD} = sub {
         # don't change $! and $? outside handler
         local ($!, $?);
     $SIG{CHLD} = sub {
         # don't change $! and $? outside handler
         local ($!, $?);
-        my $pid = waitpid(-1, WNOHANG);
-        return if $pid == -1;
-        return unless defined $children{$pid};
-        delete $children{$pid};
-        cleanup_child($pid, $?);
+        while ( (my $pid = waitpid(-1, WNOHANG)) > 0 ) {
+            delete $children{$pid};
+            cleanup_child($pid, $?);
+        }
     };
 
     while (1) {
     };
 
     while (1) {