struct task_struct *find_task_by_vpid(pid_t vnr),在当前task的namespace下根据vpid找到对应的task
其使用的例子如下:
SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
const void __user * __user *, pages,
const int __user *, nodes,
int __user *, status, int, flags)
{
struct task_struct *task;
struct mm_struct *mm;
int err;
nodemask_t task_nodes;
/* Check flags */
if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
return -EINVAL;
if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
return -EPERM;
/* Find the mm_struct */
rcu_read_lock();
task = pid ? find_task_by_vpid(pid) : current;
if (!task) {
rcu_read_unlock();
return -ESRCH;
}
}
其源码分析如下:
struct task_struct *find_task_by_vpid(pid_t vnr)
{
return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
}
可以看出find_task_by_vpid 仅仅是find_task_by_pid_ns的包装,是用当前task 所在的namespace中查找vnr对应的task.
由于仅仅是find_task_by_pid_ns的包装,所以再调用find_task_by_vpid的时候同样需要rcu_read_lock/rcu_read_unlock 的保护进程管理API之find_task_by_vpid
最新推荐文章于 2024-10-27 15:23:29 发布
本文介绍了find_task_by_vpid函数的功能及使用方法,该函数用于根据虚拟进程ID(vpid)在当前任务的命名空间中查找对应的task_struct。文中通过move_pages系统调用示例展示了如何使用此函数,并解释了其内部实现原理。
2508

被折叠的 条评论
为什么被折叠?



