linux - Linux中waitpid()的返回值

标签 linux signals waitpid

当 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() 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/

相关文章:

mysql - mysql 批处理文件中的 Tee 命令不起作用

c++ - 你如何 "buffer"UNIX信号

linux - 如何将 C 中的信号从父进程传播到自己进程组中的子进程?

c++ - Waitpid 等待已失效的子进程

linux - 在保留大小写的同时递归替换文件和目录名称

linux - XKB : Switch Overlay vs HotKeys

c - 等待所有子进程,避免挂起的进程

linux - 一步杀死并等待

Windows 上的 WPF 客户端 + Linux 服务器上的 WebService

python - 将 Python SIGINT 重置为默认信号处理程序