Created
September 22, 2015 17:03
-
-
Save tildelowengrimm/d4feedb303eba9937155 to your computer and use it in GitHub Desktop.
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/zsh | |
zmodload zsh/mathfunc | |
THRESHOLD=35 | |
CANDIDATE=$(ps -ax -o "%p|%C|%a" | grep '/opt/google/chrome/chrome' | grep 'type=gpu-process') | |
if [ "$CANDIDATE" = "" ] ; then | |
echo "["$(date --rfc-3339=seconds)"]: No Chrome GPU processes running." | |
exit 2 | |
fi | |
PID=$(echo "$CANDIDATE" | cut -d "|" -f 1) | |
CPU=$(echo "$CANDIDATE" | cut -d "|" -f 2) | |
CPU=$((int(rint($CPU)))) | |
if [ "$CPU" -gt "$THRESHOLD" ] ; then | |
kill -9 "$PID" | |
echo "["$(date --rfc-3339=seconds)"]: Killed Chrome GPU process" "$PID" "using" "$CPU" "% CPU. [Threshold was ""$THRESHOLD""%.]" | |
logger "Killed Chrome GPU process" "$PID" "using" "$CPU" "% CPU. [Threshold was ""$THRESHOLD""%.]" | |
exit 0 | |
fi | |
echo "["$(date --rfc-3339=seconds)"]: Didn't kill Chrome GPU process ""$PID"" using ""$CPU""% CPU. [Threshold is ""$THRESHOLD""%.]" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment