From 3c9864f97c9b614c6002a9d7128fcff9b39cf98d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 27 Feb 2015 08:00:12 -0800 Subject: [PATCH] JBAS-479 clean up forked children in throttle_disbatcher.pl When registering a sig handler for CHLD, we have to waitpid for child procs to clean them up or defunct procs will proliferate. Also update counts with each reaped child, since that's the only accurate way to know how many children have completed their tasks. See http://perldoc.perl.org/perlipc.html#Signals SIGCHLD Signed-off-by: Bill Erickson --- KCLS/linking/throttle_disbatcher.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/KCLS/linking/throttle_disbatcher.pl b/KCLS/linking/throttle_disbatcher.pl index 13e6a380b4..12bee51540 100755 --- a/KCLS/linking/throttle_disbatcher.pl +++ b/KCLS/linking/throttle_disbatcher.pl @@ -28,6 +28,7 @@ use Getopt::Long; use Time::localtime; +use POSIX qw/:sys_wait_h/; $SIG{CHLD} = \&sig_handler; @@ -152,8 +153,12 @@ sub dispatch { } sub sig_handler { - $running--; - $count++; + # clean up child processes + while ((my $child = waitpid(-1, WNOHANG)) > 0) { + print "reaping child $child\n"; + $running--; + $count++; + } } __END__ -- 2.11.0