subprocess and PPID

saju.pillai at gmail.com saju.pillai at gmail.com
Wed Nov 5 11:19:34 EST 2008


On Nov 5, 5:12 pm, Michele Petrazzo <michele.petra... at TOGLIunipex.it>
wrote:
> Hi all,
> I believe that this is a *nix question, but since I'm developing in
> python, I'm here.
>
> I have a code that execute into a "Popen" a command (ssh). I need that,
> if the python process die, the parent pid (PPID) of the child don't
> become 1 (like I can seen on /proc/$pid$/status ), but it has to die,
> following it's parent
> It's possible in linux and with subprocess?


AFAIK, there is no easy way to do this. If the parent python process
is doing a controlled exit, just kill the child via close() on Popen()
handle. If the parent is doing a uncontrolled exit (say via a SIGKILL
signal), you can't really do anything.

To reliably have the child exit when the parent exits, you would have
to poll for the parent from the child and do a exit when the child
detects that the parent has gone away.

-srp

>
> Thanks,
> Michele




More information about the Python-list mailing list