Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: wait4(2) do not fail with WNOHANG if there is no child



Hmmm...

I see that POSIX says ...   *about waitpid() - there is no POSIX wait4()
but waitpid() is just wait4() without the rusage arg, which is irrelevant
here)

    If waitpid() was invoked with WNOHANG set in options, it has at least
    one child process specified by pid for which status is not available,
    and status is not available for any process specified by pid, 0 is
    returned. Otherwise, -1 shall be returned, and errno set to indicate
    the error.

We don't do that, and in fact, the code in the wait sys call explicitly
does not ...

        for (;;) {      
                error = ECHILD; 
                dead = NULL;    
                        
                LIST_FOREACH(child, &parent->p_children, p_sibling) {
			[....]
		}

                if (child != NULL || error != 0 || (nohang && dead == NULL)) {
                        *child_p = child;
                        return (nohang && error == ECHILD) ? 0 : error;
                }
		[...]
	}        

That is, if WNOHANG was set ("nohang" is true) and the are no children at
all (the LIST_FOREACH never executes its body) the error would have
been ECHILD (the posix specified error for this case) then because
nohang is set, return 0...

kre



Home | Main Index | Thread Index | Old Index