我必须以非阻塞方式查找子进程的状态(正在运行/已暂停/已终止)。 我找到了这段代码,可以帮助我检测它是否正在运行/完成:
#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 */
}
此代码是否可以帮助我检测进程是否已暂停\正在睡眠? 谢谢。