waitpid, wnohang, wuntraced. How do I use these

If you pass -1 and WNOHANGwaitpid() 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.

Read the waitpid page from POSIX for more details.

Leave a Comment