Process Information by PID

T

Thomas Guettler

Hi!

I want to get some information about
a process.

I know its PID, and I need
to know the commandline.

I need something like:
ps -p $THISPID

System: Linux, Python2.2

thomas
 
P

Peter Hansen

Thomas said:
I want to get some information about
a process.

I know its PID, and I need
to know the commandline.

I need something like:

Surely you've already considered using popen? On the other hand,
using "-p" doesn't give me the command line for processes, just
the name of the command itself.

What about reading from the /proc/$PID/cmdline pseudo-file ?

-Peter
 
T

Thomas Guettler

Am Thu, 16 Oct 2003 08:56:18 -0400 schrieb Peter Hansen:
Surely you've already considered using popen? On the other hand,
using "-p" doesn't give me the command line for processes, just
the name of the command itself.

You are right. In my case the name of the command would be enough.

popen: I read the PID from a file, the background process
gets started before my script.
What about reading from the /proc/$PID/cmdline pseudo-file ?

Is this portable to other unix systems?

thomas
 
P

Peter Hansen

Thomas said:
Am Thu, 16 Oct 2003 08:56:18 -0400 schrieb Peter Hansen:


You are right. In my case the name of the command would be enough.

popen: I read the PID from a file, the background process
gets started before my script.

I think you misunderstood. Use popen like this:

outf = os.popen("ps -p %s" % PID)
outputOfPsCommand = outf.read()

and then parse the contents of the outputOfPsCommand string...

Is this portable to other unix systems?

Probably not. You said "Linux", not multi-platform...

-Peter
 
W

Wojtek Walczak

Dnia Thu, 16 Oct 2003 14:32:23 +0200, Thomas Guettler napisa³(a):
I want to get some information about
a process.

I know its PID, and I need
to know the commandline.

I need something like:

System: Linux, Python2.2

Well, for my needs I wrote procpy:

<http://www.underground.org.pl:81/gminick/tools/procpy.tar.gz>

It's a C module for python using libproc library. The install.sh script
does the work for you. Here's a little readme:

<http://www.underground.org.pl:81/gminick/pliki/README-procpy.txt>

ps. in Linux ps, w, top and so on are using libproc as well
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top