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: "email@hidden" <email@hidden>
- Date: Sat, 14 Aug 2010 00:24:34 +0100
On 13 Aug 2010, at 22:32, Greg Guerin wrote:
>> 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);
>> }
>
> The current process-group id is inherited across fork() and execve() - see their respective man pages. So if you reorder the operations so setsid() occurs before [task launch], then the child inherits automatically.
>
Hah! That does seem to have the desired effect.
> This doesn't mean the child can't change its own pgid/sid. And since you mention a shell, it's not unusual for shells to do exactly that.
>
In my simple test (one task forks/execs to bash which forks/execs 10 background sleeps) killing the process leader has the desired cascade of terminations.
Thanks and regards
Jonathan Mitchell
Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________
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