arn*_*app 2 c linux kernel process linux-kernel
我想检查我的pid进程是否从内核扩展运行.
在用户空间中,这很简单:
if (kill(pid, 0) == 0) {
printf("Process %d is running\n", pid);
} else if (errno == ESRCH) {
printf("Process %d is not running\n", pid);
} else {
printf("This shouldn't happen oO\n");
但不知何故,kill()在内核中不可用.有另一种方法可以做到这一点吗?
您可以使用pid_task()或get_pid_task()获取指向struct task_struct进程的指针.如果调用返回,NULL则该进程不存在.
请注意,您可能需要小心,因为pid可能已被回收,现在由不同的进程使用.
| 归档时间: | 
 | 
| 查看次数: | 3075 次 | 
| 最近记录: |