end child process when parent dies (on Unix)

  • Thread starter Дамјан ГеоргиевÑки
  • Start date
Ð

Дамјан ГеоргиевÑки

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?
 
L

Lawrence D'Oliveiro

Дамјан ГеоргиевÑки said:
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'm starting a Unix tool with subprocess.Popen() from a python script
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()
 
L

Lawrence D'Oliveiro

Дамјан ГеоргиевÑки said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top