Skip to content

Instantly share code, notes, and snippets.

@tildelowengrimm
Created September 22, 2015 17:03
Show Gist options
  • Save tildelowengrimm/d4feedb303eba9937155 to your computer and use it in GitHub Desktop.
Save tildelowengrimm/d4feedb303eba9937155 to your computer and use it in GitHub Desktop.
#!/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