Re: [exim-dev] can waitpid() fail?

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Philip Hazel
Datum:  
To: Marc Haber
CC: exim-dev
Betreff: Re: [exim-dev] can waitpid() fail?
On Fri, 11 Mar 2005, Marc Haber wrote:

> src/log.c has the following construction:
>
>    while (waitpid(pid, &status, 0) != pid);

>
> To my understanding, this will spin until waitpid() returns pid, but
> it will spin forever if waitpid fails.
>
> Shouldn't there be a check for error return, for example if the child
> is already dead by the time we reach this code?


If the child has already finished, waitpid will return its pid
immediately. Even when completed, children wait until their parent reaps
them (if created in the right way). These are so-called "zombie"
processes. Short of the whole OS going mad, I can't see how this can
fail. After all, the whole code is just a few lines long:

   pid = fork();
   if (pid == 0)
     { 3 lines of code }
   while (waitpid(pid, &status, 0) != pid);


Er wait, I *can* see how it can go wrong. If fork() fails ...

Noted.

-- 
Philip Hazel            University of Cambridge Computing Service,
ph10@???      Cambridge, England. Phone: +44 1223 334714.
Get the Exim 4 book:    http://www.uit.co.uk/exim-book