简体   繁体   English

当两个进程等待同一个孩子时会发生什么?

[英]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标志一起使用。

POSIX: status information POSIX:状态信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当两个进程写入mmaped文件的相同部分时会发生什么? - What happens when two processes write to same portion of a mmaped file? fork()和wait()有两个子进程 - fork() and wait() with two child processes 当多个进程尝试从同一管道读取时会发生什么? - what happens when multiple processes try to read from the same pipe? 当很多进程打开同一个特殊文件时会发生什么? - What happens when a lot of processes open the same special file? 当两个进程试图访问信号量= 0的关键部分时会发生什么? - What happens when two processes are trying to access a critical section with semaphore = 0? 当你派生一个父进程时,活动子进程会发生什么,所有活动进程都会创建另一个进程吗? 叉子(); - What happens to active child processes when you fork a parent, do all active processes create another process ? Fork(); 如何为同一父级创建4个子进程并等待4个子进程完成? - How to create 4 child processes for the same parent and wait for the 4 child's to finish? 我在XV6中杀了进程“A”,对于“A”的子进程会发生什么 - I kill process “A” in XV6 , what happens to child processes of “A” 从两个子进程写入同一文件 - Writing to the same file from two child processes 使父进程等待其子进程的正确方法是什么? - What is the correct way to make a parent process wait for its child processes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM