-sub reaper {
- my $pid;
-
- while (($pid = waitpid(-1, WNOHANG)) > 0) {
- push(@finished, [$pid, $?]);
- }
-
- $SIG{CHLD} = \&reaper;
-}
-
-sub newjob {
- my $dir = shift;
- my $pid;
-
- if (not $debug) {
- $pid = fork();
- if (not defined($pid)) {
- die("fork: $!");
- }
- }
-
- if ($debug or $pid == 0) {
- $SIG{CHLD} = 'DEFAULT';
- open(STDERR, ">$dir/log") or die("open(STDERR, >$dir/log): $!");
- exit(flac($dir));
- }
-
- verbose("new job $pid for $dir\n");
- return $pid;
-}
-
-sub deljob {
- my $i = shift;
- my $j;
- my $pid;
- my $status;
-
- $pid = $finished[$i][0];
- $status = $finished[$i][1];
-
- verbose("$pid finished (");
- if (WIFEXITED($status)) {
- verbose('exited with status ', WEXITSTATUS($status));
- } elsif (WIFSIGNALED($status)) {
- verbose('killed with signal ', WTERMSIG($status));
- } elsif (WIFSTOPPED($status)) {
- verbose('stopped with signal ', WSTOPSIG($status));
- }
- verbose(")\n");
-
- for ($j = 0; $j <= $#jobs; $j++) {
- $pid == $jobs[$j] and splice(@jobs, $j, 1) and last;
- }
-
- splice(@finished, $i, 1);
-}
-