Artificial intelligent assistant

Need script to kill python process with low CPU usage I've created a very large and complex python program and I now know it has a serious bug that I'm having a very hard time pinning down. I'm using this code in a production environment so I need a stop-gap measure to implement until I find and correct my coding issue. I need to create a bash script that I can use to check for CPU usage of my python program and kill it if it's consistently below x%. Once killed it will automatically restart on it's own. I'm using the following to get my PID and %CPU $ ps -eo pid -eo pcpu -eo command |grep python |grep pycode.py > 2940 71.9 python pycode.py How can I check %cpu, which is 71.9 above, against x% cpu and then kill the PID if needed. Also, the python program does not go runaway nor does it die. It simply drops to below 5% cpu and stays there and the UI freezes. I'm new to bash so I really don't know where to start.

Here's a crude attempt:


read -r pid cpu rest < <(ps -eo pid -eo pcpu -eo command |grep python |grep pycode.py)
if (( ${cpu%.*} < 5 )) ; then
kill -TERM $pid
fi


We use `${cpu%.*}` to truncate it to an integer, since bash can't handle floats. This only runs once; if you want to keep it going, put it on a cron job, or put it in a loop with `sleep 5` or whatever.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy df67b05a893af6ff3b0f41257ce77928