waitpid, wnohang, wuntraced. How do I use these

后端 未结 2 572
无人及你
无人及你 2021-01-30 18:02

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

2条回答
  •  长发绾君心
    2021-01-30 18:44

    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.

    Read the waitpid page from POSIX for more details.

提交回复
热议问题