等待,wnohang ,,.我如何使用这些 [英] waitpid, wnohang, wuntraced. How do I use these
问题描述
我有点困惑.据我了解,pid为-1的waitpid表示我等待所有孩子的完成,但是如果我在WNOHANG的waitpid中添加一个选项,则该选项表示如果没有完成则立即退出...这些似乎非常令人困惑.
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?
有人可以解释此选项和WUNTRACED选项吗?我不知道被追踪是什么意思.
Can someone explain this option and the WUNTRACED options? I don't know what it means to be traced.
推荐答案
如果通过-1
和WNOHANG
,waitpid()
将检查是否存在任何僵尸儿童.如果是,则收获其中之一,并返回其退出状态.如果不是,则返回0
(如果存在未终止的子代)或返回-1
(如果不存在),并且将ERRNO
设置为ECHILD
(无子进程).如果您想确定是否有任何孩子最近死亡而不必等待一个孩子死亡,这将很有用.在这方面非常有用.
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.
选项WUNTRACED
的说明如下,我对此内容无添加:
The option WUNTRACED
is documented as below, I have nothing to add to this description:
WUNTRACED
< pid指定的任何已停止的子进程的状态,以及自停止以来尚未报告过的子进程的状态,也应报告给请求进程.
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.
从 waitpid 页中进行阅读: //pubs.opengroup.org/onlinepubs/9699919799/"rel =" noreferrer> POSIX 了解详情.
Read the waitpid page from POSIX for more details.
这篇关于等待,wnohang ,,.我如何使用这些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!