On Sat, Jul 02, 2011 at 08:44:27PM +0200, Kurt J. Bosch wrote:
killall5 returns 2 if it didn't kill any processes. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/functions b/functions index 69f06eb..401e323 100644 --- a/functions +++ b/functions @@ -293,13 +293,21 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + local i + for (( i=0; i<500; i+=25 )); do + killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done
In the context of killall5, 'killed' means a signal was sent. This will cause a zombie process to hang shutdown for 2 minutes.
stat_done
stat_busy "Sending SIGKILL To Processes" - killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + local i + for (( i=0; i<100; i+=25 )); do + killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done
Ideally, this never kills anything, because all our processes exited nicely in the loop above. However, if it does successfully send a signal to a process, then we just spent the past 125 seconds waiting on the above SIGTERM spam to time out. When it does time out, we're going to spend another 25 seconds here waiting for the same process to be spammed with SIGKILL.
stat_done
run_hook "$1_postkillall" -- 1.7.1
There's probably a handful of programs who don't appreciate receiving SIGTERM every 1/4 of a second. dave