gpt4 book ai didi

linux - linux中waitpid()的返回值

转载 作者:太空狗 更新时间:2023-10-29 12:15:00 32 4
gpt4 key购买 nike

当waitpid()函数按如下方式实现时,子进程因SIGTSTP信号停止时返回什么?为什么?

waitpid(pid,&status,WUNTRACED);
其中 pid 是任何进程的进程 ID,状态是 int 类型。

它是否也会挂起调用进程,直到它找不到任何已停止或终止的子进程,或者它不会影响正在进行的进程?

最佳答案

它返回已停止的子进程的进程 ID。

POSIX 声明

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.

If wait() or waitpid() returns because the status of a child process is available, these functions shall return a value equal to the process ID of the child process for which status is reported. (...)

here .

当然,如果有多个子进程并且调用中的pid0或更小,这个返回值就更有趣了,以至于你不知道预先报告的子进程的 PID,但您可以通过任何一种方式获得它。

关于linux - linux中waitpid()的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728570/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com