[英]What happens when two processes wait for the same child?
From what I've read the default behavior for wait
/ waitpid
is to wait for a state change in a process. 从我读到的内容, wait
/ waitpid
的默认行为是等待进程中的状态更改。 What I can't find is the expected behavior of two processes waitpid
using the same pid_t
argument. 我找不到使用相同pid_t
参数的两个进程waitpid
的预期行为。
Do both return and continue execution, or is it a race condition where only one notices the state change? 两者都返回并继续执行,还是一种只有一个人注意到状态改变的竞争条件?
Only the parent can wait() for a process, and a process can of course have only one parent. 只有父级可以等待一个进程,而一个进程当然只能有一个父级。
The parent process might, however, have multiple threads. 但是,父进程可能具有多个线程。 In the case of multiple threads waiting for the same child, POSIX specifies that only one of them will see the state change. 如果有多个线程在等待同一个子线程,则POSIX指定仅其中一个线程会看到状态更改。 To allow multiple threads to see the state change, you must use waitid() with the WNOWAIT flag. 要允许多个线程查看状态更改,必须将waitid()与WNOWAIT标志一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.