update_daemon2: check for dead children before spawning

This commit is contained in:
Andrew Dolgov 2008-01-24 09:46:09 +01:00
parent e933840523
commit 5a613536c7

View file

@ -42,11 +42,7 @@
$last_checkpoint = -1; $last_checkpoint = -1;
function sigalrm_handler() { function reap_children() {
die("received SIGALRM, hang in feed update?\n");
}
function sigchld_handler($signal) {
global $children; global $children;
$tmp = array(); $tmp = array();
@ -61,9 +57,18 @@
$children = $tmp; $children = $tmp;
$running_jobs = count($children); return count($tmp);
}
function sigalrm_handler() {
die("received SIGALRM, hang in feed update?\n");
}
function sigchld_handler($signal) {
$running_jobs = reap_children();
_debug("[SIGCHLD] jobs left: $running_jobs"); _debug("[SIGCHLD] jobs left: $running_jobs");
pcntl_waitpid(-1, $status, WNOHANG); pcntl_waitpid(-1, $status, WNOHANG);
} }
@ -123,6 +128,8 @@
if ($last_checkpoint + SPAWN_INTERVAL < time()) { if ($last_checkpoint + SPAWN_INTERVAL < time()) {
reap_children();
for ($j = count($children); $j < MAX_JOBS; $j++) { for ($j = count($children); $j < MAX_JOBS; $j++) {
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid == -1) { if ($pid == -1) {