How do you check if a program or process is running when using python?you can execute OS system call.
What I want to do is have an infinite loop to check if a program is running
or not and send data to my web server to check yes or no. Is this
possible? If so how?
here i execute ps -ef and grep the required process name (or you can grep by
pid on that particular column using awk)
import os
os.system("ps -ef | grep -v grep | grep <proc_name>")
in my system it gives result 0 if the process is running
root 8749 5331 0 Jul19 pts/1 00:00:00 python>>a = os.system("ps -ef | grep -v grep | grep python")
0>>a
else gives non 0 :
256>>a = os.system("ps -ef | grep -v grep | grep python123")
a
you can check this inside while True:
I am sure there should be a far better solution that this in python.
-Venky