Skip to content

Instantly share code, notes, and snippets.

@Fang-Li
Created February 5, 2018 02:23
Show Gist options
  • Select an option

  • Save Fang-Li/0145b10add8535338bcac00687e984d9 to your computer and use it in GitHub Desktop.

Select an option

Save Fang-Li/0145b10add8535338bcac00687e984d9 to your computer and use it in GitHub Desktop.
Kill cpu occupy more than 80% of the process
#!/bin/bash
#killer.sh
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
while true;
do
ps axf -o "pid %cpu command" |grep -v bashd| awk '{if($2>=80.0) print $1}' | while read procid
do
kill -9 $procid
done
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment