I am a bit confused. As I understand, waitpid with a pid of -1 means that I wait for all child's to finish but if I add an option to the waitpid of WNOHANG, that options says to exit immediately if none have finished...These seems extremely confusing.
Why would I tell the computer to wait for child processes to finish and then immediately afterwards tell it to exit immediately if none of the childs have finished?
Can someone explain this option and the WUNTRACED options? I don't know what it means to be traced.
If you pass -1
and WNOHANG
, waitpid()
will check if any zombie-children exist. If yes, one of them is reaped and its exit status returned. If not, either 0
is returned (if unterminated children exist) or -1
is returned (if not) and ERRNO
is set to ECHILD
(No child processes). This is useful if you want to find out if any of your children recently died without having to wait for one of them to die. It's pretty useful in this regard.
The option WUNTRACED
is documented as below, I have nothing to add to this description:
WUNTRACED
The status of any child processes specified by pid that are stopped, and whose status has not yet been reported since they stopped, shall also be reported to the requesting process.