<div>I like 2) the most.  I do have access to the child.  The child is a process started with multiprocessing.Process(function).  How do I _not_ set an SID?</div><div><br></div><div>thanks,</div><div><br></div><div>--mihai</div>
<br><div class="gmail_quote">On Wed, Dec 7, 2011 at 2:50 PM, Dan Stromberg <span dir="ltr"><<a href="mailto:drsalists@gmail.com">drsalists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 12/7/11, Mihai Badoiu <<a href="mailto:mbadoiu@gmail.com">mbadoiu@gmail.com</a>> wrote:<br>
> ok, so the code is something like<br>
> #process A<br>
>   p = Process(...)<br>
>   p.daemon = 1<br>
>   p.start()   # starts process B<br>
> ...<br>
><br>
> If process A dies (say error, or ctrl-c), or finishes, then process B also<br>
> dies.  But if process A is killed with the "kill" command, then process B<br>
> soldiers on...<br>
><br>
> Any idea on how to make process B die when process A gets killed by the<br>
> "kill" command?<br>
<br>
</div>1) If all you care about is SIGTERM, SIGHUP and the like (and<br>
specifically NOT SIGKILL), you could just install a signal handler<br>
that catches any catchable signals you're interested in.  Then the<br>
signal either kills the children directly, or sets a flag that tells<br>
the main process to do some killing shortly.  Note that threads and<br>
signal handlers don't mix very well - the combination tends to make<br>
the main thread immune to control-C, whether you want it to be or not.<br>
 Also, signal handlers tend to complicate performing I/O, as you're<br>
more likely to read short blocks.<br>
<br>
2) If you need to handle SIGKILL gracefully, and you have access to<br>
the code of the child process, you could make sure that the child<br>
isn't setting a SID (?).  ssh, I believe, likes to start a new SID,<br>
making it immune to signals to the parent.  Alternatively, you could<br>
add something to the child process' main loop that polls the parent,<br>
exiting if the parent no longer exists.<br>
<br>
3) If you need to handle SIGKILL gracefully, and you don't have access<br>
to the code of the child process, you could use a single extra process<br>
that checks for the presense of the parent, and if it doesn't exist<br>
any more, then kill the children before exiting itself.<br>
</blockquote></div><br>