- 论坛徽章:
- 0
|
本帖最后由 embeddedlwp 于 2014-03-21 16:06 编辑
Q1:2.6.24引入CLONE_NEWPID之后,do_fork参数clone_flags设置了CLONE_NEWPID,那么返回给父进程的PID是父PID命名空间的PID值吗?
Q2:《深入Linux内核架构》中如下文字:Since fork returns the PID of the new task, it must be obtained. This is complicated because the
fork operation could have opened a new PID namespace if the flag CLONE_NEWPID was set. If
this is the case, then task_pid_nr_ns is required to obtain the PID that was selected for the new
process in the parent namespace, that is, the namespace of the process that issued fork.
If the PID namespace remains unchanged, calling task_pid_vnr is enough to obtain the local
PID because old and new processes will live in the same namespace.
我查看了下2.6.24的源码,task_pid_nr_ns如下:
446 pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
447 {
448 return pid_nr_ns(task_pid(tsk), ns);
449 }
pid_nr_ns如下:
433 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
434 {
435 struct upid *upid;
436 pid_t nr = 0;
437
438 if (pid && ns->level <= pid->level) {
439 upid = &pid->numbers[ns->level];
440 if (upid->ns == ns)
441 nr = upid->nr;
442 }
443 return nr;
444 }
这个函数并没有产生新PID,这是怎么回事?
Q3:引入PID命名空间之后,进程创建时,新进程在所属的PID命名空间和父PID命名空间的PID都会在此时产生吗? |
|