Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: waitpid() does not wait for process exit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: waitpid() does not wait for process exit




On 04 May 2011, at 06:13, Anatol Pomozov wrote:

if (waitpid(pid, &status, 0) < 0) {
 perror("waitpid);
 printf("fail waitpid = %d\n", pid);
}

The code looks pretty much typical, everything seems fine. But the
code fails on macosx - waitpid() returns ECHILD error. waitpid()
thinks that there is no any child with such pid. Hmm, why?

Although probably unrelated to the error you are getting, the above code is not safe. You must use something like this instead:


int res;

do {
  res = waitpid(pid, &status, 0);
} while ((res < 0) && (errno == EINTR));

if (res < 0) {
 perror("waitpid);
 printf("fail waitpid = %d\n", pid);
}

There are many low level libc routines that directly map to syscalls and which can return EINTR. In every such case you must use a loop like the above, or at least correctly deal with the special case of EINTR.


Jonas _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >waitpid() does not wait for process exit (From: Anatol Pomozov <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.