Using python to check the status of a program

J.R. j.r.gao at
Mon Dec 29 03:19:30 CET 2003

"The Jetman" <jetman516 at> wrote in message
news:a38d43b0.0312271424.70a4138c at
> 1st, which OS are we talking about ?  *IF* we're talking about
> Linux/Unix/FreeBSD, then it only takes a few lines:
>   import os
>   import string
>   f = os.popen( 'ps -ax' )
>   s = f.readlines()
>   if string.find( s, 'target_pgm' ) > -1:
>       ####  we found it, so do something....

If the process id is known, use "kill -0 pid" to check if the process is
still running.
Additional, you may need to check if it's coring even the return value of
the kill command is not 0.

More information about the Python-list mailing list