• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to assure NSTask termination when parent dies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to assure NSTask termination when parent dies


  • Subject: How to assure NSTask termination when parent dies
  • From: "email@hidden" <email@hidden>
  • Date: Fri, 13 Aug 2010 14:13:28 +0100

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 (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

  • Follow-Ups:
    • Re: How to assure NSTask termination when parent dies
      • From: Michael Ash <email@hidden>
  • Prev by Date: Re: CGColorSpaceCreateWithName on iOS
  • Next by Date: Question about UIScrollviews
  • Previous by thread: Re: CGColorSpaceCreateWithName on iOS
  • Next by thread: Re: How to assure NSTask termination when parent dies
  • Index(es):
    • Date
    • Thread