Re: How to assure NSTask termination when parent dies
Re: How to assure NSTask termination when parent dies
- Subject: Re: How to assure NSTask termination when parent dies
- From: Michael Ash <email@hidden>
- Date: Fri, 13 Aug 2010 14:29:15 -0400
On Fri, Aug 13, 2010 at 9:13 AM, email@hidden
<email@hidden> wrote:
> 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.
I'm not sure why your setpgid doesn't work. You might try a more
UNIX-oriented mailing list, such as darwin-dev. Your problem isn't
really related to Cocoa except for the part where you're using an
NSTask wrapper, and that *shouldn't* affect things....
There are a couple of other things you could try.
If your subprocess reads from standard input and exits on EOF, set its
standard input to a pipe. When your process exits, it will close its
end of the pipe. That will cause an EOF to be generated on the other
side, and it will exit.
If your subprocess regularly writes to standard output, set its
standard output to a pipe. When your process exits, it will close its
end, which causes a SIGPIPE to be generated on the other side the next
time it tries to write to it. SIGPIPE kills the process by default.
Finally, if neither of these apply to your particular subprocess, you
could make your own subprocess that DOES do these, and it could then
kill the other subprocesses when it sees your process exit.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden