Question

For some reason, I have to call waitpid twice on the same child process:

Calling the waitpid the first time and there are no errors:

waitpid(pid, &status, WUNTRACED);

The second time:

waitpid(pid, &status, WNOHANG|WUNTRACED);

An error occurred: "No child process". Is there anything wrong with my code?

Update:

If the child process have already exited after or before my first calling of waitpid, which means the parent process has reaped this child process, the second calling of waitpid then causes errors. Is this correct?

Was it helpful?

Solution

Could it be that the child terminated prior to the second waitpid() call? AFAIR, waitpid() waits for child process termination (or other change of state).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top