OSProcess: making sure that a child process always dies

Joshua Gargus schwa at fastmail.us
Tue Mar 20 23:12:35 UTC 2007


Hi David,

In order to compile the plugin on OS X (using Ian's 3.9-8 from  
squeakvm.org) I had to hack UnixOSProcessPlugin.c so that  
primitiveSetPGrp() calls 'setpgrp(0,0)' instead of 'setpgrp()'.

It appears that OS X and Linux treat these differently.  Under Linux,  
setpgrp() calls setpgid(0,0) , whereas under OS X, setpgrp is  
identical to setpgid (the sources for these assertions are,  
respectively, http://linux.about.com/library/cmd/blcmdl2_setpgrp.htm  
and 'man setpgrp' on OSX).  It appears that having primitiveSetPGrp()  
call setpgid(0,0) would be the most compatible approach.

Thanks again,
Josh



On Mar 18, 2007, at 9:48 AM, David T. Lewis wrote:

> Hi Josh,
>
> I did some more work on this problem, and came up with a good
> way to address it. You will need to build a new OSProcessPlugin
> and load the latest OSProcess, after which you can do:
>
> 	OSProcess thisOSProcess killCurrentChildrenAtExit
>
> This makes use of atexit() to arrange for any currently active child
> processes to receive a SIGTERM signal when your Squeak VM exits,
> regardless of whether the normal image #shutDown processing occurs.
> By "currently active" I mean the child processes that have already
> been started, and that are running at the time you do the
> #killCurrentChildrenAtExit.
>
> I also added primitives to support Unix setsid(), getpgid(), setpgid 
> (),
> getpgrp(), setpgrp() session management functions. You can use these
> if you want to experiment further (but I think  
> #killCurrentChildrenAtExit
> is much easier).
>
> The latest OSProcessPlugin and OSProcess are here:
>  http://www.squeaksource.com/OSProcessPlugin/VMConstruction-Plugins- 
> OSProcessPlugin-dtl.8.mcz
>  http://www.squeaksource.com/OSProcess/OSProcess-dtl.33.mcz
>
> If you try this out, please let me know if it works for you.
>
> Dave
>
> On Thu, Mar 15, 2007 at 11:12:01AM -0700, Joshua Gargus wrote:
>> Hi David,
>>
>> Thanks, that's what I had implemented.  However, the OS X VM has a
>> menu item "Quit do not save" which appears not to go through the
>> regular Squeak shutdown process.  Also, you never know when you'll
>> have to terminate an image with "extreme prejudice" :-)
>>
>> I suppose that another option would be to stash the pids in a file
>> and kill them on startup.
>>
>> Thanks to you and John for the suggestions.  I'm not a unix expert,
>> and I had no idea what support the underlying APIs had for this use
>> case.
>>
>> Cheers,
>> Josh
>>
>>
>> On Mar 15, 2007, at 4:58 AM, David T. Lewis wrote:
>>
>>> On Thu, Mar 15, 2007 at 12:15:01AM -0700, Joshua Gargus wrote:
>>>> Hi,
>>>>
>>>> Is there a way to use OSProcess on OS X (or unix in general) to  
>>>> cause
>>>> forked child processes to die when the parent Squeak process quits?
>>>
>>> You can keep track of the process proxy for the forked child
>>> process, and explicitly terminate it when you exit Squeak, possibly
>>> as part of a class #shutDown: method.
>>>
>>> For example, you can kill all child processes like this:
>>>  OSProcess thisOSProcess allMyChildren do: [:e | e terminate]
>>>
>>> Dave
>>>
>>>
>>




More information about the Squeak-dev mailing list