Re: waitpid() does not wait for process exit
Re: waitpid() does not wait for process exit
- Subject: Re: waitpid() does not wait for process exit
- From: Jonas Maebe <email@hidden>
- Date: Wed, 04 May 2011 10:32:34 +0200
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