471,873 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Re: How do you check if a program/process is running using python?

On Sunday 20 July 2008 12:08:49 am Lamonte Harris wrote:
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?
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
>>a = os.system("ps -ef | grep -v grep | grep python")
root 8749 5331 0 Jul19 pts/1 00:00:00 python
>>a
0

else gives non 0 :
>>a = os.system("ps -ef | grep -v grep | grep python123")
a
256

you can check this inside while True:

I am sure there should be a far better solution that this in python.

-Venky
Jul 19 '08 #1
0 2055

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kamuela Franco | last post: by
3 posts views Thread by Fabio Pliger | last post: by
6 posts views Thread by Pierre-Yves | last post: by
4 posts views Thread by Nick Sinclair | last post: by
5 posts views Thread by Per B. Sederberg | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.