免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1730 | 回复: 0
打印 上一主题 下一主题

[进程管理] 关于CLONE_NEWPID的疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-18 12:06 |只看该作者 |倒序浏览
本帖最后由 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都会在此时产生吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP