Linux-Pthread
来源:互联网 发布:mac系统机器码怎么查看 编辑:程序博客网 时间:2024/06/12 00:45
Detach
当其他线程调用exit(),分离的线程将会收到影响而终止。
Zombie 僵尸线程
- Not Detached;
- Non pthread_join() or wait();
僵尸进程是一个已经结束的进程/线程,但OS保留部分信息以备父进程查询, OS会在结束时清理僵尸进程。
僵尸进程在多进程环境下,父进程要长时间运行 ,期间可能创建子进程,然后子进程有退出时,但是父进程还在运行,这时就产生了zombie进程。
子进程退出后,在进程表中还要占一项,并且子进程的一些资源等待父进程回收。如果父进程没有显示地调用wait来为子进程回收资源的话,在父进程退出之前子进程就变成了僵尸进程。如果父进程退出了,僵尸子进程也消失了。
#include <unistd.h>#include <iostream>#include <pthread.h>using namespace std;int main(){ pid_t child; switch(child = fork()) { case -1: exit(0); case 0: exit(0); break; default: cout << getpid() << endl; sleep(100); } return 0;}
$ ps -aux | grep "main"xx 5718 0.0 0.0 15440 1608 pts/2 S 17:37 0:00 ./mainxx 5719 0.0 0.0 0 0 pts/2 Z 17:37 0:00 [main] <defunct>$ kill -9 5718
0 0
- linux pthread
- linux pthread
- linux pthread
- linux pthread
- linux pthread
- Linux Pthread
- linux pthread
- Linux-Pthread
- [Linux]Pthread
- linux pthread 状态和pthread终止
- Pthread 与 Linux
- pthread/Linux多线程编程
- Pthread 与 Linux
- Pthread 与 Linux
- Pthread 与 Linux
- Linux线程pthread笔记
- linux多线程pthread
- Pthread 与 Linux
- 创建对象-类-构造函数之间的关系
- 使用angularjs1.x构建前台开发框架(十二)——脏检查
- AI LEADING EVERYTHING?
- 中文乱码处理汇总
- 动态内存分配讲解
- Linux-Pthread
- 关于 super 关键字
- 构造函数与getter和setter的区别
- MySQL多表联表查询
- CCF NOI1027 数字之和
- go语言调用append之后是否重新分配内存?
- 多项式求和
- 多线程学习笔记(二)之线程安全问题
- 【LeetCode】53. Maximum Subarray