Linux waitpid
2016-03-16 20:53
876 查看
pid_t waitpid(pid_t pid, int *status, int options);
options包括(但不限于)以下三个
__WCLONE Wait for "clone" children only. If omitted then wait for "non-clone" children only. (A "clone" child is one which delivers no signal, or a signal other than SIGCHLD to its parent upon termination.) This option is ignored if __WALL is also specified. __WALL (since Linux 2.4) Wait for all children, regardless of type ("clone" or "non-clone"). __WNOTHREAD (since Linux 2.4) Do not wait for children of other threads in the same thread group. This was the default before Linux 2.4.
__WALL
就是所有children;__WCLONE
clone children;一般就是pthread_create出来的线程;至于上面说不给parent发SIGCHLD,找了一下内核代码,如下
if (clone_flags & CLONE_THREAD) { p->exit_signal = -1; p->group_leader = current->group_leader; p->tgid = current->tgid; }
exit_signal置为 -1 了;
__WNOTHREAD
排除同一线程组里其它线程的children;~~~~~~~~~~~~~~~~~~~~~~~~~~~
线程的ppid
进程 p 通过pthread_create创建了线程 t ,t 的ppid是啥呢?原以为是 p 的 pid,测了一下发现不是,而是 p 的 ppid;
还是找内核代码,如下
if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) { p->real_parent = current->real_parent; p->parent_exec_id = current->parent_exec_id; }
pthread_create创建线程时设置了 CLONE_THREAD,通过strace很容易验证;
知道了答案再想想,也是,p和t是同一个线程组的,是平级关系,ppid也应是相同的;
用喜闻乐见的方式总结一下
A,A1,A2是一个线程组(A通过pthread_create创建A1,A2;下同);
B,B1是一个线程组;
C,C1是一个线程组;
对A来说,WNOTHREAD排除的就是A1,A2的children;
略丑,凑合看。
相关文章推荐
- java-模拟tomcat服务器
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程