#!/bin/sh
-# $Id$
+#
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
+# Copyright (C) 2010 INRIA
+#
COMMAND=$(basename $0)
cd $(dirname $0)
+THISNODE=$(basename $(pwd -P) | sed -e s,qemu-,,)
cd ..
# somehow qemu-system-x86_64 show up in pgrep as qemu-system-x86
-COMMANDS_TO_KILL="qemu qemu-system-x86_64 qemu-system-x86"
+COMMANDS_TO_KILL="qemu qemu-system-x86_64 qemu-system-x86 qemu-kvm"
function usage () {
echo "Usage: $COMMAND -l"
echo " lists current qemu processes"
echo "usage: $COMMAND hostname"
echo " kill qemu instance for that node"
+ echo "usage: $COMMAND this"
+ echo " kill qemu instance that was started in this directory"
echo "usage: $COMMAND"
echo " kill all instances of [$COMMANDS_TO_KILL]"
exit 1
hostnames="$@"
if [[ -n "$hostnames" ]] ; then
for hostname in $hostnames; do
+ [ $hostname == this ] && hostname=$THISNODE
nodedir=qemu-$hostname
cat $nodedir/qemu.pid 2> /dev/null
done
hostnames="$@"
if [[ -n "$hostnames" ]] ; then
for hostname in $hostnames; do
+ [ $hostname == this ] && hostname=$THISNODE
nodedir=qemu-$hostname
kill_from_file $nodedir/qemu.pid
done
else
- echo "Killing all processes mathing $COMMANDS_TO_KILL"
- for command in $COMMANDS_TO_KILL ; do
- pkill -x $command
- done
+ pids=$(list_pids)
+ if [ -n "$pids" ] ; then
+ echo "Killing all processes matching $COMMANDS_TO_KILL"
+ for pid in $pids; do
+ echo Killing $pid
+ kill $pid
+ done
+ else
+ echo "No process found that match $COMMANDS_TO_KILL"
+ fi
fi
}
while getopts "lk" opt; do
case $opt in
l) OPT_LIST=true ;;
- k) OPT_GREP=true ;;
*) usage ;;
esac
done