diff options
author | Yang Tse <yangsita@gmail.com> | 2009-12-21 14:36:01 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2009-12-21 14:36:01 +0000 |
commit | bdd376398051522a1c930949142d6066f4518a3d (patch) | |
tree | c242953feea026b09ea068477ffee227fcad7e92 | |
parent | 1cfa52b67d649fd58de803290c6ba04d6615b891 (diff) |
Reap processes dead children ASAP without blocking
-rw-r--r-- | tests/ftp.pm | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/ftp.pm b/tests/ftp.pm index 6218bb482..d19d0c70f 100644 --- a/tests/ftp.pm +++ b/tests/ftp.pm @@ -63,7 +63,7 @@ sub processexists { # get rid of the certainly invalid pidfile unlink($pidfile) if($pid == pidfromfile($pidfile)); # reap its dead children, if not done yet - # waitpid($pid, &WNOHANG); + waitpid($pid, &WNOHANG); # negative return value means dead process return -$pid; } @@ -112,6 +112,8 @@ sub killpid { else { print("RUN: Process with pid $pid already dead\n") if($verbose); + # if possible reap its dead children + waitpid($pid, &WNOHANG); push @reapchild, $pid; } } @@ -128,6 +130,8 @@ sub killpid { print("RUN: Process with pid $pid gracefully died\n") if($verbose); splice @signalled, $i, 1; + # if possible reap its dead children + waitpid($pid, &WNOHANG); push @reapchild, $pid; } } @@ -143,12 +147,14 @@ sub killpid { print("RUN: Process with pid $pid forced to die with SIGKILL\n") if($verbose); kill("KILL", $pid); + # if possible reap its dead children + waitpid($pid, &WNOHANG); push @reapchild, $pid; } } } - # Reap processes dead children. + # Reap processes dead children for sure. if(defined(@reapchild)) { foreach my $pid (@reapchild) { if($pid > 0) { |