r47528 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47527‎ | r47528 | r47529 >
Date:01:53, 20 February 2009
Author:tstarling
Status:ok
Tags:
Comment:
* Don't kill child processes during normal termination, that will leave the last few jobs in the queue uncompleted
* Snicker-resistant terminology
Modified paths:
  • /trunk/phase3/maintenance/runJobs.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/runJobs.php
@@ -27,7 +27,7 @@
2828 $wgCaches = array();
2929 unset( $wgMemc );
3030
31 - // Spawn the children
 31+ // Create the child processes
3232 $children = array();
3333 for ( $childId = 0; $childId < $procs; $childId++ ) {
3434 $pid = pcntl_fork();
@@ -39,7 +39,7 @@
4040 break;
4141 }
4242
43 - $children[] = $pid;
 43+ $children[$pid] = true;
4444 }
4545 if ( $pid ) {
4646 // Parent process
@@ -56,18 +56,17 @@
5757 } else {
5858 declare (ticks=1) { $status = $status; }
5959 }
60 - } while ( $deadPid == -1 && !$termReceived );
61 - // Kill the remaining children
62 - // If they're already dead, say due to SIGTERM, then they'll be zombies until
63 - // pcntl_waitpid() below, so the PID won't be reused.
64 - foreach ( $children as $childPid ) {
65 - if ( $childPid != $deadPid ) {
66 - posix_kill( $childPid, SIGTERM );
 60+ if ( $deadPid > 0 ) {
 61+ unset( $children[$deadPid] );
6762 }
68 - }
69 - foreach ( $children as $childPid ) {
70 - pcntl_waitpid( $childPid, $status );
71 - }
 63+ // Respond to TERM signal
 64+ if ( $termReceived ) {
 65+ foreach ( $children as $childPid => $unused ) {
 66+ posix_kill( $childPid, SIGTERM );
 67+ }
 68+ $termReceived = false;
 69+ }
 70+ } while ( count( $children ) );
7271 // All done
7372 exit( 0 );
7473 }

Status & tagging log