struct pid *find_vpid(int nr) 用于根据nr也就是namespace下的局部pid找到对应的struct pid结构体
其使用的例子如下:
这个系统调用的参赛arg就是局部pid。
int f_setown(struct file *filp, unsigned long arg, int force)
{
enum pid_type type;
struct pid *pid = NULL;
int who = arg, ret = 0;
type = PIDTYPE_PID;
if (who < 0) {
/* avoid overflow below */
if (who == INT_MIN)
return -EINVAL;
type = PIDTYPE_PGID;
who = -who;
}
rcu_read_lock();
if (who) {
pid = find_vpid(who);
if (!pid)
ret = -ESRCH;
}
if (!ret)
__f_setown(filp, pid, type, force);
rcu_read_unlock();
return ret;
}
其源码分析如下:
struct pid *find_vpid(int nr)
{
return find_pid_ns(nr, task_active_pid_ns(current));
}
这个函数仅仅调用find_pid_ns,根据nr,在当前task所在的namespace下找到nr对应的struct pid结构体
struct pid
{
atomic_t count;
unsigned int level;
/* lists of tasks that use this pid */
struct hlist_head tasks[PIDTYPE_MAX];
struct rcu_head rcu;
struct upid numbers[1];
};进程管理API之find_vpid
最新推荐文章于 2026-06-13 09:09:36 发布
本文介绍了find_vpid函数,该函数用于根据局部pid在当前进程的namespace中查找对应的structpid结构体。此外,还详细展示了如何在代码中使用此函数,并提供了具体的实现源码。


2597

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



