Re: [NSTask] -launch return
Re: [NSTask] -launch return
- Subject: Re: [NSTask] -launch return
- From: Greg Guerin <email@hidden>
- Date: Tue, 9 Jun 2009 09:43:51 -0700
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