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?

有帮助吗?

解决方案

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top