Created
January 31, 2014 14:06
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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