My app generates a task using NSTask().

If my app is killed or calls abort() - which equates to raise(SIGABRT) - then 
it would be desirable that the child die too.

If I have the code for the launched task then a kqueue comes to the rescue:
http://old.nabble.com/Ensure-NSTask-terminates-when-parent-application-does-td22510014.html

However, if I launch a shell this option isn't available.
So process groups come to mind.

However calling setpgid (see code below) seems to fail however with RPERM - 
operation not allowed.
Is this an OS X POSIX process implementation detail or a consequence of the 
interior NSTask fork() implementation?

I know that there are some OS NSTask substitutes available but I am not certain 
that that is the answer.

My only thought is to install a Cocoa friendly signal handler and explicitly 
terminate the child.
But there is no guarantee that this sort of post trauma cleanup will always 
succeed.

Process group code:

        // launch the task
        [task launch];

        pid_t group = setsid(); 
        if (group == -1) { 
        NSLog(@"setsid() == -1"); 
           group = getpgrp(); 
        } 
        if (setpgid([task processIdentifier], group) == -1) { 
           NSLog(@"unable to put task into same group as self: errno = %i", 
errno); 
        } 
        NSLog(@"new task process id = %i", [task processIdentifier]);
        NSLog(@"pgid = %i", group);

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to