diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-04-04 23:03:45 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-04-04 23:03:45 +0000 |
commit | faed8372f7fab4fdaadd83875b323d193e10ca08 (patch) | |
tree | 81e64598fe47b0cbf559360cc2c9591b3038913e | |
parent | f9eacfa91548bbca696c78883cb939f767a7b43a (diff) | |
download | iurt-faed8372f7fab4fdaadd83875b323d193e10ca08.tar iurt-faed8372f7fab4fdaadd83875b323d193e10ca08.tar.gz iurt-faed8372f7fab4fdaadd83875b323d193e10ca08.tar.bz2 iurt-faed8372f7fab4fdaadd83875b323d193e10ca08.tar.xz iurt-faed8372f7fab4fdaadd83875b323d193e10ca08.zip |
(kill_for_good) more readable (?) ; comment it
-rw-r--r-- | lib/Iurt/Process.pm | 28 |
1 files 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 { |