• 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: Wait until task is finished?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Wait until task is finished?
      • From: Jeff Harrell <email@hidden>
References: 
 >Re: Wait until task is finished? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Build failed since Dec Dev Tools gcc update ?
  • Next by Date: Re: Wait until task is finished?
  • Previous by thread: Re: Wait until task is finished?
  • Next by thread: Re: Wait until task is finished?
  • Index(es):
    • Date
    • Thread