tags:

views:

336

answers:

1

When I wait on a specific running process group that is a child process, WIFEXITED returns true saying the process exited? Is this the way it works? Seems there is something I am not understanding....

if ( waitpid(-pgid, &pstatus, WUNTRACED|WNOHANG ) == -1)
    perror("Wait error");

if ( WIFEXITED(pstatus) ) {
    strncpy(buf,  "Exited", buf_size);
    return 0;
+2  A: 

As you specified WNOHANG I think waitpid is returning 0 and pstatus has the value it had before so WIFEXITED is not working with updated data.

if WNOHANG was specified and one or more child(ren) specified by pid exist, but have not yet changed state, then 0 is returned.

Arkaitz Jimenez
Ah, I did reinitialize to 0, but now I sort of understand. but I don't quite understand how to tell if something is still running or if it exited (without blocking).
Kyle Brandt
If any of your children changed status(died) waitpid will return a positive number.
Arkaitz Jimenez
Oh I understand now... I Need to take both the return value and the status value to get the status of the process. (Return value is not just for error or not). Thank you!
Kyle Brandt
The WIFE has left and the children died from the shock.
James Morris
@James Morris: I thought the WIFE was EXCITED that the children were still alive...
just somebody