Detecting if Linux Program Running

Stian Husemoen stianh at ifi.uio.no
Sat Mar 18 22:45:42 CET 2000


Joseph C. Kopec wrote:
>Is there any easy way using Python under Linux to detect whether a
>particular executable is running?  Thanks in advance.

Best tip is to check the output of "os.popen('ps')" .. to some this will
seem like cheating, but trust me it isn't. <wink>
Another way could be to poke around in the /proc-directory...

If you already have a pid and want to check if the program is running, you
can try to send it signal 0 by doing a "os.kill(pid,0)". This will raise an
OSError if this isn't a running process.

-- 

Stian Husemoen <stianh>



More information about the Python-list mailing list