Retrieving pids on a linux process
thomas at xs4all.net
Sat May 13 23:08:01 CEST 2000
On Sat, May 13, 2000 at 09:29:25AM -0500, Olmy wrote:
> 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.
> So, this is the best I've come up with:
> pid_output = commands.getoutput('/sbin/pidof myprocess')
This is probably the easiest way, though using 'ps' is probably more
portable. The linux manpage does not mention the availability of the pidof
command, but the BSDI machines we use do not have it. It may be a SysV-only
command, as it's based on killall5, which is SysV killall.
(retrieving process info requires reading kernel data, usually through
/dev/kmem or such, and is *highly* system dependant. 'ps' is a common enough
tool to use in a shell wrapper, but unfortunately, there are two basic
flavours of 'ps', BSD and SysV, and even similar 'ps's can give different
output :P Linux 'ps', version 2.0, for instance supports both BSD and SysV
output & options, plus a few totally new ones.)
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list