
| The Following User Says Thank You to frullewulle For This Useful Post: | ||
#!/bin/bash
# This checks every 1/2 minute and kills if
# sensorfwd process is eating more than 8% CPU for 1 minute
TERM=linux
export TERM
kill_count=0
while true; do
sensors_pid=$(ps aux | grep sensorfwd | grep -v grep | awk '{print $2}')
# If the process has crashed it may not be running,
# so we restart it
if [ -z $sensors_pid ]; then
echo "sensorfwd not found"
# Before restarting the service, we must first kill the sensors.qcom process
sensors_qcom=$(ps aux | grep sensors.qcom | grep -v grep | awk '{print $2}')
kill $sensors_qcom
systemctl restart sensorfwd
else
cpu_usage=$(top -b -p $sensors_pid -n1 | grep $sensors_pid | awk '{print $9}')
echo $cpu_usage
echo "CPU Usage of sensorfwd: ${cpu_usage/.*}"
if [[ ${cpu_usage/.*} -ge 8 ]]; then
if [[ $kill_count -ge 1 ]]; then
echo "CPU Usage of sensorfwd too high restarting..."
systemctl restart sensorfwd
kill_count=0
else
echo "CPU Usage of sensorfwd too high! Setting kill_count + 1"
kill_count=$((kill_count+1))
fi
else
echo "Nothing to do"
fi
fi
sleep 30
done
| The Following User Says Thank You to beobachter For This Useful Post: | ||