kernel: efficient way to find task_struct by pid?

2019-01-15 09:44发布

Is there an efficient way of finding the task_struct for a specified pid, without iterating through the task_struct list?

2条回答
2楼-- · 2019-01-15 10:12

What's wrong with using one of the following?

extern struct task_struct *find_task_by_vpid(pid_t nr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
            struct pid_namespace *ns);
查看更多
Fickle 薄情
3楼-- · 2019-01-15 10:20

If you want to find the task_struct from a module, find_task_by_vpid(pid_t nr) etc. are not going to work since these functions are not exported.

In a module, you can use the following function instead:

pid_task(find_vpid(pid), PIDTYPE_PID);
查看更多
登录 后发表回答