Capture PID of child process

Bernhard Herzog bh at
Tue Aug 5 18:01:13 CEST 2003

klappnase at (klappnase) writes:

> self.pp = popen2.Popen3(cmd)
> cmdpid =
> However I found that the PID returned by is not the PID of
> the process of interest, but the PID of a subshell in which this child
> process is running.

If cmd is a string popen will start a sub-shell so that'd the pid you
get. You could try to prefix your command with exec so that your
command's process replaces the shell process (see the shell

Alternatively you could use a list of strings as the command so that no
shell is used in the first place, i.e. "prog param" would become
["prog", "param"]. This approach has the advantage that you don't have
to worry about shell quoting but it's less portable because it's not
even documented (I'll file a bug report for that).


Intevation GmbH                       

More information about the Python-list mailing list