[arch-projects] [initscripts] [PATCH 13/13] functions: Speed up reboot/shutdown by recognizing killall5 exit code 2

Kurt J. Bosch kjb-temp-2009 at alpenjodel.de
Sun Jul 3 16:31:15 EDT 2011


killall5 returns 2 if it didn't find any processes to send to. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time.
---
 functions |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/functions b/functions
index 9cc9cc6..71d0312 100644
--- a/functions
+++ b/functions
@@ -310,14 +310,25 @@ kill_everything() {
 	run_hook "$1_prekillall"
 
 	# Terminate all processes
+	# and wait until timeout or killall5 reports all done
+	# Unfortunately killall5 does not support the 0 signal, so just
+	# use SIGCONT for checking (which should be ignored).
 	stat_busy "Sending SIGTERM To Processes"
+		local i
 		killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null
-		sleep 5
+		for (( i=0; i<20 && $?!=2; i++ )); do
+			sleep .25 # 1/4 second
+			killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null
+		done
 	stat_done
 
 	stat_busy "Sending SIGKILL To Processes"
+		local i
 		killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null
-		sleep 1
+		for (( i=0; i<4 && $?!=2; i++ )); do
+			sleep .25 # 1/4 second
+			killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null
+		done
 	stat_done
 
 	run_hook "$1_postkillall"
-- 
1.7.1



More information about the arch-projects mailing list