Chinaunix首页 | 论坛 | 博客
  • 博客访问: 616995
  • 博文数量: 69
  • 博客积分: 1891
  • 博客等级: 上尉
  • 技术积分: 1359
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-20 23:38
文章分类

全部博文(69)

文章存档

2012年(46)

2011年(23)

分类: LINUX

2012-02-12 20:04:23

copy_process的第二部工作是取得PID
  1. nr = task_pid_vnr(p);
该函数的进一步定义如下:
  1. static inline pid_t task_pid_vnr(struct task_struct *tsk)
  2. {
  3.     return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
  4. }
继续。。
  1. pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
  2.             struct pid_namespace *ns)
  3. {
  4.     pid_t nr = 0;

  5.     rcu_read_lock();
  6.     if (!ns)
  7.         ns = current->nsproxy->pid_ns;
  8.     if (likely(pid_alive(task))) {
  9.         if (type != PIDTYPE_PID)
  10.             task = task->group_leader;
  11.         nr = pid_nr_ns(task->pids[type].pid, ns);
  12.     }
  13.     rcu_read_unlock();

  14.     return nr;
  15. }
继续
  1. pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
  2. {
  3.     struct upid *upid;
  4.     pid_t nr = 0;

  5.     if (pid && ns->level <= pid->level) {
  6.         upid = &pid->numbers[ns->level];
  7.         if (upid->ns == ns)
  8.             nr = upid->nr;
  9.     }
  10.     return nr;
  11. }
这个代码的作用是取得pid在指定命名空间ns下的pid

这整段代码的作用就是取得task在当前命名空间下的局部pid。

阅读(1988) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~