From c6bacf009791cfe985cc864c4c4214c5899ee5f9 Mon Sep 17 00:00:00 2001 From: "slamm%netscape.com" Date: Wed, 1 Mar 2000 17:49:52 +0000 Subject: [PATCH] Better process killer. git-svn-id: svn://10.0.0.236/trunk@61972 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/tools/tinderbox/build-seamonkey.pl | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/mozilla/tools/tinderbox/build-seamonkey.pl b/mozilla/tools/tinderbox/build-seamonkey.pl index ca6181b4f0a..4ddbf079489 100755 --- a/mozilla/tools/tinderbox/build-seamonkey.pl +++ b/mozilla/tools/tinderbox/build-seamonkey.pl @@ -11,7 +11,7 @@ use POSIX qw(sys_wait_h strftime); use Cwd; use File::Basename; # for basename(); use Config; # for $Config{sig_name} and $Config{sig_num} -$::Version = '$Revision: 1.78 $ '; +$::Version = '$Revision: 1.79 $ '; sub PrintUsage { die < $target_pid; - sleep 3; # Give it 3 seconds to actually die - my $pid = waitpid($target_pid, WNOHANG()); - return if ($pid == $target_pid and WIFEXITED($?)) or $pid == -1; - } - for (my $ii=0; $ii < 3; $ii++) { - kill 'KILL' => $target_pid; - sleep 2; # Give it 2 second to actually die - my $pid = waitpid($target_pid, WNOHANG()); - return if ($pid == $target_pid and WIFEXITED($?)) or $pid == -1; + my $start_time = time; + + # Try to kill and wait 10 seconds, then try a kill -9 + for my $sig ('TERM', 'KILL') { + kill $sig => $target_pid; + my $interval_start = time; + while (time - $interval_start < 10) { + my $pid = waitpid($target_pid, WNOHANG()); + if (($pid == $target_pid and WIFEXITED($?)) or $pid == -1) { + my $secs = time - $start_time; + $secs = $secs == 1 ? '1 second' : "$secs seconds"; + print_log "Process killed. Took $secs to die.\n"; + return; + } + sleep 1; + } } die "Unable to kill process: $target_pid"; }