检查C中的运行进程
发布时间:2020-12-16 05:34:29 所属栏目:百科 来源:网络整理
导读:有人可以告诉我如何检查一个具有给定进程ID的unix进程是否在C程序中运行.我知道我可以调用system()并使用ps命令,但是我不想调用system(). 解决方法 使用 kill(2): if (kill(pid,0) == 0) { /* process is running or a zombie */} else if (errno == ESRCH)
有人可以告诉我如何检查一个具有给定进程ID的unix进程是否在C程序中运行.我知道我可以调用system()并使用ps命令,但是我不想调用system().
解决方法
使用
kill(2):
if (kill(pid,0) == 0) { /* process is running or a zombie */ } else if (errno == ESRCH) { /* no such process with the given pid is running */ } else { /* some other error... use perror("...") or strerror(errno) to report */ } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |