Wait () / waitpid () returns 1, not the pid of the child, how to fix this?

this sequel How to compress additional parameters of the header function when the parent signal is told to kill the child (c)?

In my reaper (), I am trying to get the child pid that the parent is about to finish (this is not a cruel word). but wait () does not return the pid of the child; instead, it returns 1. I cannot find a document for return value 1 anywhere. Any heads?

void    reaper(int sig)
{
    int status, killedpid;

    while(killedpid = (/*waitpid(-1, &status, WNOHANG)*/wait(&status)) >= 0)
    {
        printf("reaper %d killed %d\n", getpid(), killedpid);
    }
}

My results:

reaper 5933 killed 1 //actual child pid is 5936

Thank you in advance!

+5
source share
1 answer

- ( precedence ):

if ( killedpid = ( wait( &status ) >= 0 )) { ...

killedpid TRUE, 1 C. , , -Wall -pedantic:

if (( killedpid = wait( ... )) >= 0 ) { ...
+13

All Articles