Mailing List Archive

How to find out the pid of a running program?
I'd like tknow if there is a way of getting the pid of a program running,
using python commands?

/Peter Torstenson
How to find out the pid of a running program? [ In reply to ]
Peter Torstenson wrote:
>
> I'd like tknow if there is a way of getting the pid of a program running,
> using python commands?

Use the getpid() function from the posix module which is imported
automatically when you import the os module. Don't import the posix
module directly. Do it via the os module since this will afford you
code better portablility. Refer to the Python Library Reference for
more info.
How to find out the pid of a running program? [ In reply to ]
> Peter Torstenson wrote:
> >
> > I'd like tknow if there is a way of getting the pid of a program
running,
> > using python commands?
>
> Use the getpid() function from the posix module which is imported
> automatically when you import the os module. Don't import the posix
> module directly. Do it via the os module since this will afford you
> code better portablility. Refer to the Python Library Reference for
> more info.

I think I didn't express myself clearly!
I want to find out the pid of another program than the one I give
the command from!
Ex. the pid of the running pppd.
The getpid() function returns the pid of the python program it self as far
as I understand.
How to find out the pid of a running program? [ In reply to ]
Peter Torstenson wrote:
>
> I want to find out the pid of another program than the one I give
> the command from!

How about os.popen("ps -ef") or whatever works on your OS. You can then
search
for 'pppd' and get its pid. Not a great solution, as 'ps' flags and
formats vary across platforms. OTOH, is you needed to know the owner of
the process or other info, you'd get it all in one shot.

--
Bear Technology Making Montana safe for Grizzlies

http://people.montana.com/~bowman/