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.