this is a follow up to How to squeeze in additional parameters to a reaper function when a parent is signalled to kill a child (c)?
In my reaper(), I try to obtain the child's pid the parent is about to finish (non-brutal word here). but wait() does not return the pid of the child; instead, it returns 1. I can't find a doc for return value of 1 anywhere. Any heads up?
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!