• 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
Re: NSTask terminates when NSApplication exits
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask terminates when NSApplication exits


  • Subject: Re: NSTask terminates when NSApplication exits
  • From: Keary Suska <email@hidden>
  • Date: Wed, 18 Jan 2012 14:13:01 -0700

On Jan 18, 2012, at 11:59 AM, Andrew wrote:

> I am trying to write a program that maintains different installs of
> another program including launching the program. To do so, I am using
> NSTask. Now when I quit my cocoa app. the NSTask app dies. The task
> that the NSTask is running is a Java program, not sure if that makes a
> difference. According to what I have read, the application should keep
> running even when the parent task exits. I am running my cocoa app
> from in XCode4, not sure if that has any effect on it. Could it be
> that I am not specifying standard* streams so when the parent app
> quits, those streams are closed and thus the process?
>
> I can probably find out the answer by trying different things, but I'd
> like to get a better insight for what is going on and why the child
> task is terminating.

Any special handling of NSTask aside, Mac OS X uses Unix-based process control which closes all child processes when the parent is closed. Since your sub-program is Java you may be able to detach the child process. This is usually accomplished by the sub-program by executing a low-level fork(). It may need to be followed by an exec() to fully detach the process. Note that you can't do this with Cocoa/Objective-C (at least Apple says you shouldn't…)

Alternatively (and probably preferably) you could use launchd/Launch Services as recommended. Useful reading: http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

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: NSTask terminates when NSApplication exits
      • From: Ken Thomases <email@hidden>
References: 
 >NSTask terminates when NSApplication exits (From: Andrew <email@hidden>)

  • Prev by Date: Re: NSTask terminates when NSApplication exits
  • Next by Date: Re: NSTask terminates when NSApplication exits
  • Previous by thread: Re: NSTask terminates when NSApplication exits
  • Next by thread: Re: NSTask terminates when NSApplication exits
  • Index(es):
    • Date
    • Thread