进程管理API之find_pid_ns

struct pid *find_pid_ns(int nr, struct pid_namespace *ns) 用于从namespace 下的pid找到对应的pid结构体
其中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];
};


其使用的例子如下:
static int convert_fuse_file_lock(struct fuse_conn *fc,
				  const struct fuse_file_lock *ffl,
				  struct file_lock *fl)
{

		rcu_read_lock();
		fl->fl_pid = pid_vnr(find_pid_ns(ffl->pid, fc->pid_ns));
		rcu_read_unlock();

}

其源码分析如下:
首先根据ns和nr在pid_hash中找到对应的项,即pid_hash[pid_hashfn(nr, ns)],然后遍历pid_hash[pid_hashfn(nr, ns)]
找到其中的pid_chain,并复制给pnr,如果pnr的成员变量nr和ns分别等于形参中的nr和nr,则pnr就是我们我们要找到
最后通过pid中的成员变量upid返回pid结构体的指针,如果没有找到的话则返回null.

struct pid *find_pid_ns(int nr, struct pid_namespace *ns)
{
	struct upid *pnr;

	hlist_for_each_entry_rcu(pnr,
			&pid_hash[pid_hashfn(nr, ns)], pid_chain)
		if (pnr->nr == nr && pnr->ns == ns)
			return container_of(pnr, struct pid,
					numbers[ns->level]);

	return NULL;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值