我想知道进程是否正在运行。我不想使用任何系统(“”)命令。是否有任何基于 C 的函数可以让您知道进程是否正在运行?
我想提供进程名称并想知道它是否正在运行。
谢谢,
最佳答案
当然,使用 kill(2)
:
#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);
If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID.
因此只需对要检查的进程的进程 ID 调用 kill(pid, 0)
并查看是否出现错误 (ESRCH
)。
关于c - 如何查找进程是否在 C 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11785936/