- global $running_jobs;
- if ($running_jobs > 0) $running_jobs--;
- print posix_getpid() . ": SIGCHLD received, jobs left: $running_jobs\n";
+ global $children;
+
+ $tmp = array();
+
+ foreach ($children as $pid) {
+ if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) {
+ array_push($tmp, $pid);
+ } else {
+ _debug("[SIGCHLD] child $pid reaped.");
+ }
+ }
+
+ $children = $tmp;
+
+ $running_jobs = count($children);
+
+ _debug("[SIGCHLD] jobs left: $running_jobs");