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
最新推荐文章于 2023-02-19 09:45:16 发布