Capture PID of child process

klappnase klappnase at web.de
Tue Aug 5 11:36:13 EDT 2003


Hello, everyone,

I am running python2.2.2 on a linux box.
I want to call a shell command and get the PID of this child process
so I have the possibility to abort the child process while it is still
running.

I tried the popen2 module for that:

self.pp = popen2.Popen3(cmd)
cmdpid = self.pp.pid

However I found that the PID returned by self.pp.pid is not the PID of
the process of interest, but the PID of a subshell in which this child
process is running.
So if I do

os.kill(cmdpid, 9)

the subshell is killed, but the process I actually wanted to stop is
happily running on.

Does anyone have a clue what to do about that? Any help would be very
appreciated.

Thank you in advance

Michael




More information about the Python-list mailing list