On Thu, Dec 10, 2009 at 3:01 PM, Bryan Murdock <[email protected]> wrote:
> On Thu, Dec 10, 2009 at 2:10 PM, Andrew McNabb <[email protected]> wrote:
>> 2) Alternatively, you can create a new process group with setpgid() (and
>> you might have to create a new session, too, with setsid()--I'd have to
>> think about this a little bit more).  If your Python script is a process
>> group leader, then all other processes in the group should be killed if
>> your script (the process group leader) exits.
>
> Very cool.  Any idea if it would work under cygwin?

Highly doubtful.

Yes, I'm replying to myself.  I didn't know anything about process
groups and sessions, so I found this to read:

http://www.win.tue.nl/~aeb/linux/lk/lk-10.html

And discovered the -j option to ps, and that there is a setsid utility
that you can use to run a program in it's own session, thus making it
a session leader.  I ran my little python script (without the SIGTERM
handling) like so:

setsid subproc.py

And using ps -j I can see that it is the session leader of it's own
session and group, and the bash while loop is a member of that session
and group.  However, when I kill subproc.py, the while loop continues
to run.  As before.  Apparently killing a session leader doesn't kill
everything in the session.  In fact, things are worse (for what I'm
trying to do).  Now if I ctrl-c to try and kill subproc.py, it lives
on, apparently not receiving the KeyboardInterrupt.  Without setsid,
ctrl-c kills them both.  Very interesting.  I wish I understood this
better.

Bryan
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to