Index: trunk/phase3/maintenance/runJobs.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | $wgCaches = array(); |
29 | 29 | unset( $wgMemc ); |
30 | 30 | |
31 | | - // Spawn the children |
| 31 | + // Create the child processes |
32 | 32 | $children = array(); |
33 | 33 | for ( $childId = 0; $childId < $procs; $childId++ ) { |
34 | 34 | $pid = pcntl_fork(); |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | break; |
41 | 41 | } |
42 | 42 | |
43 | | - $children[] = $pid; |
| 43 | + $children[$pid] = true; |
44 | 44 | } |
45 | 45 | if ( $pid ) { |
46 | 46 | // Parent process |
— | — | @@ -56,18 +56,17 @@ |
57 | 57 | } else { |
58 | 58 | declare (ticks=1) { $status = $status; } |
59 | 59 | } |
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] ); |
67 | 62 | } |
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 ) ); |
72 | 71 | // All done |
73 | 72 | exit( 0 ); |
74 | 73 | } |