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 <glgue...@amug.org> To: list-cocoa-dev <cocoa-dev@lists.apple.com> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/erg_consultant%40yahoo.com This email sent to erg_consult...@yahoo.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com