我想知道进程的状态。我想我可以使用等待家庭功能,但实际上我不想等待过程,只需检查状态并继续。只需检查c状态进程
我希望像
checkStatusOfProcess(&status);
if(status == WORKING) {
//do something
} else if(status == exited) {
//do something else
} else \\I dont care about other states
我想知道进程的状态。我想我可以使用等待家庭功能,但实际上我不想等待过程,只需检查状态并继续。只需检查c状态进程
我希望像
checkStatusOfProcess(&status);
if(status == WORKING) {
//do something
} else if(status == exited) {
//do something else
} else \\I dont care about other states
然后你想使用的功能waitpid
与WNOHANG
选项:
#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 */
}
我想你想waitpid
与WNOHANG
。
waitpid(pid, &status, WNOHANG);
与信号0杀了它,并检查返回值。
那会继续执行? – gvalero87 2010-11-17 00:20:32
@gvalero,对。 – 2010-11-17 00:21:35