Skip to main content
Question

bash script to check if an app stop running

  • April 26, 2018
  • 1 reply
  • 0 views

Forum|alt.badge.img+4

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

Forum|alt.badge.img+14

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?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings