5 THISNODE=$(basename $(pwd -P) | sed -e s,qemu-,,)
8 # somehow qemu-system-x86_64 show up in pgrep as qemu-system-x86
9 COMMANDS_TO_KILL="qemu qemu-system-x86_64 qemu-system-x86"
12 echo "Usage: $COMMAND -l"
13 echo " lists current qemu processes"
14 echo "usage: $COMMAND hostname"
15 echo " kill qemu instance for that node"
16 echo "usage: $COMMAND this"
17 echo " kill qemu instance that was started in this directory"
18 echo "usage: $COMMAND"
19 echo " kill all instances of [$COMMANDS_TO_KILL]"
23 function list_pids () {
25 if [[ -n "$hostnames" ]] ; then
26 for hostname in $hostnames; do
27 [ $hostname == this ] && hostname=$THISNODE
28 nodedir=qemu-$hostname
29 cat $nodedir/qemu.pid 2> /dev/null
32 for command in $COMMANDS_TO_KILL; do
38 function kill_from_file () {
40 if [ -f $file ] ; then
46 echo "Could not find file $file - that qemu was killed already"
50 function kill_pids () {
52 if [[ -n "$hostnames" ]] ; then
53 for hostname in $hostnames; do
54 [ $hostname == this ] && hostname=$THISNODE
55 nodedir=qemu-$hostname
56 kill_from_file $nodedir/qemu.pid
60 if [ -n "$pids" ] ; then
61 echo "Killing all processes matching $COMMANDS_TO_KILL"
67 echo "No process found that match $COMMANDS_TO_KILL"
72 function show_pids () {
73 pids=$(list_pids "$@")
74 if [ -n "$pids" ] ; then
75 ps $pids | grep -v $COMMAND || echo Nothing to show
82 while getopts "lk" opt; do
91 if [ -n "$OPT_LIST" ] ; then