Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2871

Re: How to get a PID of a child process from a process openden with Popen()

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!prichard.zen.co.uk.POSTED!not-for-mail
From Nobody <nobody@nowhere.com>
Subject Re: How to get a PID of a child process from a process openden with Popen()
Date Fri, 08 Apr 2011 20:28:43 +0100
User-Agent Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
Message-Id <pan.2011.04.08.19.28.06.47000@nowhere.com>
Newsgroups comp.lang.python
References <d405cb62-f0e7-4db8-a2d7-41fc800a3ab9@glegroupsg2000goo.googlegroups.com>
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Lines 18
Organization Zen Internet
NNTP-Posting-Host 6488de82.news.zen.co.uk
X-Trace DXC=G9`3EK2jRY640h<YX4NfQ:0g@SS;SF6n7RiiCXJE[K>7b^f7@N:5[R3ImJb1Y7BL`4TI45FU\ZQc3
X-Complaints-To abuse@zen.co.uk
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2871

Show key headers only | View raw


On Fri, 08 Apr 2011 07:43:41 -0700, Miki Tebeka wrote:

>> 	p = subprocess.Popen(shlex.split("kdesu -u test program"))
>> 
>> How can I aquire the PID of the program which kdesu starts?
> 
> You can run "ps --ppid <p.pid>" and get the line containing test program.
> The first field there should be the child process id.

This will fail if the kdesu process has terminated at that point (the
documentation doesn't say whether it waits for the child to terminate).
Once a process' parent has terminated, it's PPID will become 1 (i.e. it
will be "adopted" by the init process).

There isn't a robust solution to the OP's problem. It's typically
impossible to determine whether one process is an ancestor of another if
any of the intermediate processes have terminated.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How to get a PID of a child process from a process openden with Popen() Miki Tebeka <miki.tebeka@gmail.com> - 2011-04-08 07:43 -0700
  Re: How to get a PID of a child process from a process openden with Popen() Nobody <nobody@nowhere.com> - 2011-04-08 20:28 +0100
    Re: How to get a PID of a child process from a process openden with Popen() Chris Angelico <rosuav@gmail.com> - 2011-04-09 08:35 +1000

csiph-web