Linux waitpid
来源:互联网 发布:js强制弹窗 编辑:程序博客网 时间:2024/05/16 01:38
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;
略丑,凑合看。
0 0
- Linux waitpid
- linux : waitpid函数
- linux waitpid wait (转)
- linux中的waitpid函数
- Linux waitpid用WNOHANG
- linux的waitpid函数
- Linux wait/waitpid详解
- linux中waitpid系统调用
- linux中waitpid系统调用
- linux中waitpid系统调用
- linux中waitpid系统调用
- linux中waitpid系统调用
- linux中waitpid系统调用
- linux进程(fork,waitpid)
- linux中waitpid系统调用
- linux中waitpid函数用法
- linux中waitpid系统调用
- linux进程(fork,waitpid)
- 对model的解归档
- JAVA中的TCP通信(多线程)
- atoi的用法
- 【LeetCode】160. Intersection of Two Linked Lists
- GC垃圾回收机制与内存泄漏
- Linux waitpid
- c#webservice的简单示例
- 设计模式笔记
- PAT Basic level practise 1002
- Android千变万化TextView(SpannableString全解析)
- hadoop的log日志查错
- HDU 1698 线段树成段更新
- js笔记
- bbs 网站开发中常见前端问题及解决