Capture PID of child process

Aaron S. Hawley Aaron.Hawley at uvm.edu
Tue Aug 5 11:52:09 EDT 2003


self.pp.tochild.close() ?

this doesn't give you the process ID (if that is your purpose), but does
appear to kill it (if that is your purpose).

/a

On Tue, 5 Aug 2003, klappnase wrote:

> 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