Created
December 27, 2018 12:52
-
-
Save hpez/e0e552052d2ebbd83792fcf6090732ca to your computer and use it in GitHub Desktop.
A gist to kill processes taking more than i% cpu. Useful for closing huge processes really fast and rescuing!
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 | |
output="$(sudo ps -eo %cpu,pid --sort -%cpu)" | |
while read -r line; do | |
words=($line) | |
st=$(echo ${words[0]}'>'5 | bc -l) # Change the number '5' to any number kill the processes taking more than that percent of cpu | |
if [ "$st" = "1" ]; | |
then | |
echo ${line} | |
exec sudo kill -9 ${words[1]} | |
fi | |
done <<< "$output" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment