Created
July 10, 2018 22:45
-
-
Save DRVTiny/5e036343253fe4c0f356fe7b4c6d7c47 to your computer and use it in GitHub Desktop.
Safely kill all anoying processes (chrome for example :))
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
#!/bin/bash | |
[[ $1 == '-x' ]] && { export TRACE=1; shift; set -x; } | |
proc=${1:-chrome} | |
declare -a pids | |
declare -i c=-1 | |
while pids=($(pgrep $proc)); do | |
kill ${pids[@]} | |
(( c++ )) || { | |
bash <<'EOSH' & | |
sleep 3 | |
kill $PPID | |
[[ -d /proc/$PPID ]] && { | |
sleep 0.02; | |
[[ -d /proc/$PPID ]] && kill -9 $PPID | |
} | |
EOSH | |
childPID=$! | |
} | |
sleep 0.01 | |
done | |
[[ $childPID && -d /proc/$childPID ]] && \ | |
kill -9 $childPID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment