bash script to check if an app stop running

tranatisoc
New Contributor II

a brief summary -

i would like to check if an application has completely stop running by checking the %cpu. this application when not running is not at 0.0. it idles around ~ 0.4. however, sometimes i see the cpu dips below 0.4 or sometimes 0.0 for a brief second, then rebound higher. so my logic below would echo 'stop running' then exit out of the loop (which is not true because it dips quickly then rebound).

i have the following script, but not working as intended:

while :
do num1=$(ps aux | grep "Name_Of_App" | head -1 | awk '{print $3}') num2=0.4 if (( $(echo "$num1 > $num2" | bc -l) )); then echo "running" else echo "not running"

break fi
done

is there a better solution?

thanks

1 REPLY 1

thebrucecarter
Contributor II

Random off the top of my head, make it respond dead twice (or more) in a row before you declare it not running?

Second random idea, make it update a semaphore if it is still running and check the semaphore file?