From faed8372f7fab4fdaadd83875b323d193e10ca08 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Wed, 4 Apr 2012 23:03:45 +0000 Subject: (kill_for_good) more readable (?) ; comment it --- lib/Iurt/Process.pm | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Iurt/Process.pm b/lib/Iurt/Process.pm index 38939a5..e94a04c 100644 --- a/lib/Iurt/Process.pm +++ b/lib/Iurt/Process.pm @@ -362,20 +362,26 @@ sub clean { sub kill_for_good { my ($pid) = @_; + + # try SIGALARM first: kill 14, $pid; sleep 1; waitpid(-1, POSIX::WNOHANG); - if (getpgrp $pid != -1) { - kill 15, $pid; - sleep 1; - waitpid(-1, POSIX::WNOHANG); - if (getpgrp $pid != -1) { - print STDERR "WARNING: have to kill -9 pid $pid\n"; - kill 9, $pid; - sleep 1; - waitpid(-1, POSIX::WNOHANG); - } - } + + return if getpgrp $pid == -1; + + # try to kill it gently then: + kill 15, $pid; + sleep 1; + waitpid(-1, POSIX::WNOHANG); + + return if getpgrp $pid == -1; + + # try harder to kill it if it hasn't cooperate: + print STDERR "WARNING: have to kill -9 pid $pid\n"; + kill 9, $pid; + sleep 1; + waitpid(-1, POSIX::WNOHANG); } sub sudo { -- cgit v1.2.1