Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2844 > unrolled thread
| Started by | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| First post | 2011-04-08 07:43 -0700 |
| Last post | 2011-04-09 08:35 +1000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | Miki Tebeka <miki.tebeka@gmail.com> |
|---|---|
| Date | 2011-04-08 07:43 -0700 |
| Subject | Re: How to get a PID of a child process from a process openden with Popen() |
| Message-ID | <d405cb62-f0e7-4db8-a2d7-41fc800a3ab9@glegroupsg2000goo.googlegroups.com> |
> 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.
HTH
--
Miki Tebeka <miki.tebeka@gmail.com>
http://pythonwise.blogspot.com
[toc] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-04-08 20:28 +0100 |
| Message-ID | <pan.2011.04.08.19.28.06.47000@nowhere.com> |
| In reply to | #2844 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-04-09 08:35 +1000 |
| Message-ID | <mailman.166.1302302125.9059.python-list@python.org> |
| In reply to | #2871 |
On Sat, Apr 9, 2011 at 5:28 AM, Nobody <nobody@nowhere.com> wrote: > 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. Upstart and gdb can both detect forks and follow the child. But I think that's getting into some serious esoteria that's unlikely to be of much practical use here. Chris Angelico
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web