简体   繁体   中英

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. What I can't find is the expected behavior of two processes waitpid using the same pid_t argument.

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. To allow multiple threads to see the state change, you must use waitid() with the WNOWAIT flag.

POSIX: status information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM