Re: Wait until task is finished?
Re: Wait until task is finished?
- Subject: Re: Wait until task is finished?
- From: "Alastair J.Houghton" <email@hidden>
- Date: Tue, 24 Jun 2003 23:50:32 +0100
On Tuesday, June 24, 2003, at 10:48 pm, Nick Zitzmann wrote:
On Monday, June 23, 2003, at 11:22 AM, Chad Armstrong wrote:
Is it possible to start an NSTask, but then have the original program
wait until the task is finished before continuing on to run along the
original path?
Start my task. [myTask launch];
Wait until task is done. ???
Do something else. NSLog(@"Foo");
What about doing something like...
[myTask launch];
while ([myTask isRunning] == YES)
{
sleep(1);
}
Polling (like the above) is poor style when it isn't necessary. A
better solution might be something like the following:
int status;
pid_t pid;
/* Start the task */
[myTask launch];
/* Wait for the task to finish */
pid = [myTask processIdentifier];
while (waitpid(pid, &status, 0) != pid);
/* Do something else */
NSLog(@"Finished");
The code above hasn't been tested, but should do what you want; the
reason for the loop containing the waitpid() is that it is possible
that a signal could cause the function to return -1 and set errno to
EINTR, in which case you will need to go around again.
Kind regards,
Alastair.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.