• 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] -launch return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSTask] -launch return


  • Subject: Re: [NSTask] -launch return
  • From: Erg Consultant <email@hidden>
  • Date: Tue, 9 Jun 2009 16:00:39 -0700 (PDT)

I have no interest whatsoever in termination notifications - only in launch notifications. Once I know my child process is, in fact, running and I have its pid, I want the whole mess including the NSTask to go away. And as I mentioned before, the entire thing has to complete within one-routine. This code runs in a method which returns whether or not the child has been launched - so I can't use the notifications which only come in after the main event loop has been run later.

Erg




________________________________
From: Greg Guerin <email@hidden>
To: list-cocoa-dev <email@hidden>
Sent: Tuesday, June 9, 2009 9:43:51 AM
Subject: Re: [NSTask] -launch return

Erg Consultant wrote:

>                         [ launchTask launch ];
>
>                         // Wait 'til  is running...
>
>                         while( ![ launchTask isRunning ] )
>                         {
>                             ;    // Spin
>                         }


This approach seems misguided.

The docs for -launch say an NSInvalidArgumentException is raised if a new process can't be created.  So if you're not getting an NSInvalidArgumentException, then logic suggests that the child process has been launched.

Next, since NSTask is almost certainly using one of the Posix forking functions to create the child process, then it's certain that if the process is created, it has a process-id.  So the whole premise of having to wait for another condition in order to have a process-id is misguided.

Worse, the spin-loop could hang forever.  That's because there's no guarantee that the process hasn't terminated between -launch and -isRunning.  It might have terminated for a reason you didn't expect.  You also don't know how the scheduler will run things, so the parent process could be delayed in its return, and/or the child could exit very quickly.  Death by race condition in a spin-lock.

Your code releases the NSTask after getting its pid.  However, the docs for NSTaskDidTerminateNotification in the NSTask reference say that the notification won't be sent for a released task.  It's unclear whether you intend the NSTask to be long-lived or short-lived, or whether you expect to receive this notification later.

  -- GG

_______________________________________________

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




_______________________________________________

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

References: 
 >Re: [NSTask] -launch return (From: Greg Guerin <email@hidden>)

  • Prev by Date: Re: self Changes on Open Panel
  • Next by Date: re-making connections with a different controller
  • Previous by thread: Re: [NSTask] -launch return
  • Next by thread: Re: [NSTask] -launch return
  • Index(es):
    • Date
    • Thread