当 waitpid() 函数按以下方式实现时,当子进程因 SIGTSTP 信号而停止时,它返回什么?为什么?
waitpid(pid,&status,WUNTRACED);
其中 pid 是任意进程的进程 ID,status 是 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()
orwaitpid()
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 whichstatus
is reported. (...)
here .
如果有多个子进程并且调用中的pid
为0
或更少,那么这个返回值当然更有趣,这样你就不会知道预先报告的子进程的 PID,但您可以通过任何一种方式获得它。
关于linux - Linux中waitpid()的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728570/