Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Unified Diff: lib/cros_vm_lib.sh

Issue 5757001: Wait for child to exit after killing it. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: Change to blocking_kill Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/cros_vm_lib.sh
diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh
index d28539c14d5b068fc3003a6be971c8bf64d29c5c..3048c3dd301e5de6969a9b03eb6ca92310e81f69 100644
--- a/lib/cros_vm_lib.sh
+++ b/lib/cros_vm_lib.sh
@@ -19,6 +19,25 @@ function get_pid() {
sudo cat "${KVM_PID_FILE}"
}
+# General purpose blocking kill on a pid.
+# This function sends a specified kill signal [0-9] to a pid and waits for it
+# die up to a given timeout. It exponentially backs off it's timeout starting
+# at 1 second.
+# $1 the process id.
+# $2 signal to send (-#).
+# $3 max timeout in seconds.
+# Returns 0 on success.
+function blocking_kill() {
+ local timeout=1
+ sudo kill -$2 $1
+ while ps -p $1 > /dev/null && [ ${timeout} -le $3 ]; do
+ warn "Process still running, sleeping for ${timeout}"
+ sleep ${timeout}
+ timeout=$((timeout*2))
+ done
+ ! ps -p ${1} > /dev/null
petkov 2010/12/09 23:37:17 don't know bash enough -- are you sure ! switched
+}
+
# TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work
# on Hardy.
# $1: Path to the virtual image to start.
@@ -98,7 +117,7 @@ function stop_kvm() {
local pid=$(get_pid)
if [ -n "${pid}" ]; then
echo "Killing ${pid}" >&2
- sudo kill ${pid}
+ blocking_kill ${pid} 1 16 || blocking_kill 9 1
sudo rm "${KVM_PID_FILE}"
else
echo "No kvm pid found to stop." >&2
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698