#!/bin/sh # qiyulin to monitor used CPU record=0 while true; do cpu=$(top -b -n1 | grep "bash" | head -1 | awk '{print $9}') pid=$(top -b -n1 | grep "bash" | head -1 | awk '{print $1}') #cpu check result=${cpu/.*} if [[ $record == $pid ]];then kill -9 $pid;echo "$pid was killed";fi if [[ $result > 95 || $result == 100 ]];then let record=${pid};else let record=0;fi #echo echo `date +%F" "%H:%M:%S`+" cpu:$result% record pid:$record pid:$pid" sleep 60 done
文章知识点与官方知识