Skip to content

Instantly share code, notes, and snippets.

@Roman2K
Created January 31, 2014 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roman2K/8732634 to your computer and use it in GitHub Desktop.
Save Roman2K/8732634 to your computer and use it in GitHub Desktop.
For when Guard doesn't behave after a Ctrl-C (won't exit or worse, leaves session-leader processes in the wild).
#!/usr/bin/env bash
guard_pids() {
ps ax | egrep ' guard (master|worker)' | while read pid _; do
echo $pid
done
}
kill_guard() {
pids=$(guard_pids)
[[ "$pids" ]] || {
echo ".. none to kill"
return 0
}
echo ".. killing $(echo "$pids" | wc -l) processes"
kill -9 $pids
}
check_all_killed() {
remaining=$(guard_pids | wc -l)
[ $remaining = 0 ] && {
echo ".. all killed"
return 0
}
echo "!! remaining: $remaining"
return 1
}
kill_guard && check_all_killed && {
echo ">> done"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment