Retrieving pids on a linux process

Olmy olmy at thistledown.org
Sat May 13 10:29:25 EDT 2000


Good morning,

I was curious as to whether any one knew of a python library 
function to retrieve the PID on a running linux process referenced 
by name. This would not have been a process started by python.

I've gone thru os and commands and didn't see anything that grabbed me.
 
(os.getpid() returns the process of the python shell and os.getppid() 
returns the process of the unix shell that invoked the python shell)


So, this is the best I've come up with:

pid_output = commands.getoutput('/sbin/pidof myprocess')

(this returns a string with all of the pids listed in it, separated by 
spaces. easy to split and run atoi on)

Any better suggestions or any useful functions I've missed?

thanks,

jeff





More information about the Python-list mailing list