From: Tim Starling Date: Fri, 20 Feb 2009 01:53:40 +0000 (+0000) Subject: * Don't kill child processes during normal termination, that will leave the last... X-Git-Tag: 1.31.0-rc.0~42781 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=5005a56a5075e9db6e38a8eca8f576e8339f5dde;p=lhc%2Fweb%2Fwiklou.git * Don't kill child processes during normal termination, that will leave the last few jobs in the queue uncompleted * Snicker-resistant terminology --- diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index ee6d0dc11c..68efb74914 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -27,7 +27,7 @@ if ( isset( $options['procs'] ) ) { $wgCaches = array(); unset( $wgMemc ); - // Spawn the children + // Create the child processes $children = array(); for ( $childId = 0; $childId < $procs; $childId++ ) { $pid = pcntl_fork(); @@ -39,7 +39,7 @@ if ( isset( $options['procs'] ) ) { break; } - $children[] = $pid; + $children[$pid] = true; } if ( $pid ) { // Parent process @@ -56,18 +56,17 @@ if ( isset( $options['procs'] ) ) { } else { declare (ticks=1) { $status = $status; } } - } while ( $deadPid == -1 && !$termReceived ); - // Kill the remaining children - // If they're already dead, say due to SIGTERM, then they'll be zombies until - // pcntl_waitpid() below, so the PID won't be reused. - foreach ( $children as $childPid ) { - if ( $childPid != $deadPid ) { - posix_kill( $childPid, SIGTERM ); + if ( $deadPid > 0 ) { + unset( $children[$deadPid] ); } - } - foreach ( $children as $childPid ) { - pcntl_waitpid( $childPid, $status ); - } + // Respond to TERM signal + if ( $termReceived ) { + foreach ( $children as $childPid => $unused ) { + posix_kill( $childPid, SIGTERM ); + } + $termReceived = false; + } + } while ( count( $children ) ); // All done exit( 0 ); }