如何(以编程方式)查找子进程是否在c(unix)中已挂起/正在休眠

时间:2019-04-21 08:32:20

标签: c unix process

我必须以非阻塞方式查找子进程的状态(正在运行/已暂停/已终止)。 我找到了这段代码,可以帮助我检测它是否正在运行/完成:

#include <sys/types.h>
#include <sys/wait.h>

int status;
pid_t return_pid = waitpid(process_id, &status, WNOHANG); /* WNOHANG def'd in wait.h */
if (return_pid == -1) {
    /* error */
} else if (return_pid == 0) {
    /* child is still running */
} else if (return_pid == process_id) {
    /* child is finished. exit status in   status */
}  

此代码是否可以帮助我检测进程是否已暂停\正在睡眠? 谢谢。

0 个答案:

没有答案
相关问题