Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > end child process when parent dies (on Unix)

Reply
Thread Tools

end child process when parent dies (on Unix)

 
 
Дамјан Георгиевски
Guest
Posts: n/a
 
      11-17-2008
Hi all,
I'm starting a Unix tool with subprocess.Popen() from a python script
and I want the child to be killed when the parent (my script) ends for
whatever reason *including* if it gets killed by SIGKILL.

For normal situations I can send a signal to the pid of the Popen object.
But not if the script ends abnormally (SIGKILL etc).

AFAIK there were some tricks with process leaders and stuff like that so if
someone remembers the exact semantics of that could refresh my memory.



--
дамјан ( http://softver.org.mk/damjan/ )

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-17-2008
Дамјан Георгиевски wrote:

> I'm starting a Unix tool with subprocess.Popen() from a python script
> and I want the child to be killed when the parent (my script) ends for
> whatever reason *including* if it gets killed by SIGKILL.


A Linux-specific solution is prctl(2).
 
Reply With Quote
 
 
 
 
Дамјан Георгиевски
Guest
Posts: n/a
 
      11-17-2008
>> I'm starting a Unix tool with subprocess.Popen() from a python script
>> and I want the child to be killed when the parent (my script) ends
>> for whatever reason *including* if it gets killed by SIGKILL.

>
> A Linux-specific solution is prctl(2).


I've tried this in a test C program... exactly what I need. Now if I
could slip this between the fork and exec in subprocess.Popen()


--
дамјан ( http://softver.org.mk/damjan/ )

In theory, there is no difference between theory and practice.
But, in practice, there is.
 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      11-17-2008
Дамјан Георгиевски wrote:

>>> I'm starting a Unix tool with subprocess.Popen() from a python script
>>> and I want the child to be killed when the parent (my script) ends
>>> for whatever reason *including* if it gets killed by SIGKILL.

>>
>> A Linux-specific solution is prctl(2).

>
> I've tried this in a test C program... exactly what I need. Now if I
> could slip this between the fork and exec in subprocess.Popen()


An obvious way, if you're trying to hack something without the source, is to substitute your own executable which does the prctl before execing the real executable.
 
Reply With Quote
 
Miles
Guest
Posts: n/a
 
      11-18-2008
On Mon, Nov 17, 2008 at 2:51 AM, Дамјан Георгиевски wrote:
>>> I'm starting a Unix tool with subprocess.Popen() from a python script
>>> and I want the child to be killed when the parent (my script) ends
>>> for whatever reason *including* if it gets killed by SIGKILL.

>>
>> A Linux-specific solution is prctl(2).

>
> I've tried this in a test C program... exactly what I need. Now if I
> could slip this between the fork and exec in subprocess.Popen()


preexec_fn, perhaps?

http://docs.python.org/library/subpr...process-module

-Miles
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
a simple program to illustrate that child process does not shareresources with parent process sree.harsha.sn@gmail.com C Programming 4 11-09-2008 03:59 AM
Pass from parent to child, then update parent with child value... Noel Dolan Javascript 0 07-18-2004 05:52 PM
Proc::Background killing parent process when child dies Paul Clements Perl Misc 2 02-11-2004 01:49 AM
How does a parent thread know when a child dies rp Java 4 11-24-2003 05:13 PM



Advertisments