On Sunday 20 July 2008 12:08:49 am Lamonte Harris wrote:
you can execute OS system call.
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
0
else gives non 0 :
256
you can check this inside while True:
I am sure there should be a far better solution that this in python.
-Venky
How do you check if a program or process is running when using python?
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?
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
>>a = os.system("ps -ef | grep -v grep | grep python")
>>a
else gives non 0 :
>>a = os.system("ps -ef | grep -v grep | grep python123")
>>a
>>a
you can check this inside while True:
I am sure there should be a far better solution that this in python.
-Venky