Skip to content

Instantly share code, notes, and snippets.

@DRVTiny
Created July 10, 2018 22:45
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 DRVTiny/5e036343253fe4c0f356fe7b4c6d7c47 to your computer and use it in GitHub Desktop.
Save DRVTiny/5e036343253fe4c0f356fe7b4c6d7c47 to your computer and use it in GitHub Desktop.
Safely kill all anoying processes (chrome for example :))
#!/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