(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
参考:https://www.tutorialspoint.com/zombie-and-orphan-processes-in-linux
参考:http://www.geekride.com/orphan-zombie-process/

zombie进程、orpahn进程是在linux中常被提到的进程。它们有着各自的特点,被系统识别标示出来。

orphan进程

孤儿进程:orphan
父进程终止,子进程还在执行;子进程被init-1号进程接管;
orphan进程是指进程还在执行,进程的父进程已经终止或结束;
有意创建的孤儿进程,类似于我们主动后台起的服务或是后台执行一个长时间的任务,这个是一个比较常见的情况;
无意创建的孤儿进程,类似于父进程异常终止了。
Orphan processes are those processes that are still running even though their parent process has terminated or finished.
A process can be orphaned intentionally or unintentionally.
An intentionally orphaned process runs in the background without any manual support. This is usually done to start an indefinitely running service or to complete a long-running job without user attention.
An unintentionally orphaned process is created when its parent process crashes or terminates. Unintentional orphan processes can be avoided using the process group mechanism.

在linux系统或类linux系统中,当父进程中止,子进程仍在执行这种情况,会立刻被重新指定父进程,把子进程的父进程指向1号进程-init进程;不过进程依然是orphan进程,因为原父进程已经终止。
In Linux/Unix like operating systems, as soon as parents of any process are dead, re-parenting occurs, automatically.
Re-parenting means processes whose parents are dead, means Orphaned processes, are immediately adopted by special process “init”.
Thing to notice here is that even after re-parenting, the process still remains Orphan as the parent which created the process is dead,

zombie进程

僵尸进程:zombie
父进程在持续运行中,子进程终止,父进程未使用wait检查子进程终止状态;此时子进程的终止状态始终保存在process table中。
A zombie process is a process whose execution is completed but it still has an entry in the process table.
Zombie processes usually occur for child processes, as the parent process still needs to read its child’s exit status.
Once this is done using the wait system call, the zombie process is eliminated from the process table. This is known as reaping the zombie process.
A diagram that demonstrates the creation and termination of a zombie process is given as follows

zobmie进程不再使用系统资源,但是会保留它的进程id;如果有许多的zombie进程,进程id就会被占用很多,可能会导致新进程的创建,因为进程id用完了。
Zombie processes don’t use any system resources but they do retain their process ID.
If there are a lot of zombie processes, then all the available process ID’s are monopolized by them. This prevents other processes from running as there are no process ID’s available.

zombie状态查看

显示所有zombie进程
ps -elf|head -1; ps -elf| awk ‘{if ($2 == “Z”) {print $0}}’

执行zombie测试程序:./a.out 12
(下面有测试程序代码样例)

[top]命令可以查到zombie进程数量:
top - 14:31:43 up 2:39, 6 users, load average: 0.15, 0.52, 0.64
Tasks: 597 total, 1 running, 595 sleeping, 0 stopped, 12 zombie

[ps -fu]命令可以看到进程状态
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
testuser 14454 0.0 0.0 4220 496 pts/4 S+ 14:32 0:00 _ ./a.out 12
testuser 14455 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14456 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14457 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14458 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14459 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14460 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14461 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14462 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14463 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14464 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14465 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]
testuser 14466 0.0 0.0 0 0 pts/4 Z+ 14:32 0:00 _ [a.out]

orphan状态查看

显示所有orphan进程:
ps -elf | head -1; ps -elf | awk ‘{if ($5 == 1 && $3 != “root”) {print $0}}’

执行arphan测试程序:./a.out 3
(下面有测试程序代码样例)

[ps -fu]命令可以看到进程状态
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
testuser 19193 0.0 0.0 4220 92 pts/4 S 14:37 0:00 ./a.out 3
testuser 19192 0.0 0.0 4220 92 pts/4 S 14:37 0:00 ./a.out 3
testuser 19191 0.0 0.0 4216 88 pts/4 S 14:37 0:00 ./a.out 3

[ps -ef|grep a.out]命令查看进程父进程变成了init-1
UID PID PPID C STIME TTY TIME CMD
testuser 19191 1 0 14:37 pts/4 00:00:00 ./a.out 3
testuser 19192 1 0 14:37 pts/4 00:00:00 ./a.out 3
testuser 19193 1 0 14:37 pts/4 00:00:00 ./a.out 3

关于processs stat code说明
PROCESS STATE CODES
Here are the different values that the s, stat and state output
specifiers (header “STAT” or “S”) will display to describe the state of
a process.
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being
traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct (“zombie”) process, terminated but not reaped by its
parent.

   For BSD formats and when the stat keyword is used, additionalcharacters may be displayed:<    high-priority (not nice to other users)N    low-priority (nice to other users)L    has pages locked into memory (for real-time and custom IO)s    is a session leaderl    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)+    is in the foreground process group

orphan测试代码

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
int main(int argc, char** argv){int subproc = 1;if (argc == 2){subproc = atoi(argv[1]);}printf("start of parent: %d\n", getpid());int pid = 0;for (int i=0; i<subproc; i++){pid = fork();if (pid == 0){break;}else{printf("create child proc: %d\n", pid);}}if (pid == 0){getchar();printf("end of child: %d\n", getpid());}else{printf("end of parent: %d\n", getpid());}return 0;
}

zombie测试代码

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
int main(int argc, char** argv){int subproc = 1;if (argc == 2){subproc = atoi(argv[1]);}printf("start of parent: %d\n", getpid());int pid = 0;for (int i=0; i<subproc; i++){pid = fork();if (pid == 0){break;}else{printf("create child proc: %d\n", pid);}}if (pid == 0){printf("end of child: %d\n", getpid());}else{getchar();printf("end of parent: %d\n", getpid());}return 0;
}

最后再标注一个问题点:orphan与zombie相同吗?
两者较明显的不同;
orphan进程是一个运行着的进程,alive;
zombie进程是一个终止了的进程但在进程表中仍有记录,not alive;
Orphan process are totally different from Zombie processes.
Zombie processes are the ones which are not alive but still have entry in process table.

(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)

zombie进程与orphan进程相关推荐

  1. linux defunct 进程,Linux僵尸进程(Zombie or defunct)

    僵尸进程(Zombie or defunct)关于Linux僵尸进程,一般是由于子进程结束的时候,会有一些资源没有释放掉,直到父进程结束或者由父进程去处理它才可以! www.cit.cn 僵尸进程就是 ...

  2. php defunct,通过swoole观察僵尸进程和孤儿进程出现和消亡

    声明:维基百科上没有僵死进程的词条,这里认为僵死进程同僵尸进程,即ZOMBIE. 一.定义 什么是僵尸进程 维基百科的定义:在类UNIX系统中,僵尸进程是指完成执行(通过exit系统调用,或运行时发生 ...

  3. python僵尸进程和孤儿进程_进程3.0——进程状态与僵尸进程、孤儿进程

    进程3.0--进程状态与僵尸进程.孤儿进程 进程状态 一个进程的生命周期可以划分为一组状态,这些状态刻画了整个进程.进程状态即体现一个进程的生命状态 一般来说,进程有五种状态:创建状态:进程在创建时需 ...

  4. 快速理解孤儿进程和僵尸进程

    下面是我很久以前在读APUE(<Unix环境高级编程>)对孤儿进程和僵尸进程的理解,为了便于记忆,采用打比方的方式予以解释. (当然不一定精准,后面我会贴出wikipedia上的专业解释. ...

  5. 孤儿进程、僵尸进程和进程退出(通俗易懂)

    系列文章目录 该文章主要是针对面试做大致的了解,通俗易懂!!! 一.孤儿进程  父进程运行结束,但子进程还在运行(未运行结束),这样的子进程就称为孤儿进程(orphan Process).每当出现一个 ...

  6. 【进程控制(进程退出、孤儿进程、僵尸进程)_Linux】

    01 / 进程退出 02 / 孤儿进程 03 / 僵尸进程 04 / 进程回收 wait()函数 退出信息相关宏函数 waitpid()函数 01 / 进程退出 //标准C库函数 #include & ...

  7. 守护进程、僵尸进程、孤儿进程

    守护进程.僵尸进程.孤儿进程 守护进程(Daemon Process) 定义 守护进程又称Daemon进程(精灵进程),是Linux中的后台服务进程. 它的生命周期较长,通常独立于控制终端并且周期性地 ...

  8. Linux中的进程控制:进程退出、孤儿进程、僵尸进程 概念及代码示例 [Linux高并发服务器开发]

    目录 一.进程退出 二.孤儿进程 三.僵尸进程 一.进程退出 #include <stdlib.h> void  exit ( int status ); #include <uni ...

  9. 启动进程 问号_有两个这样的进程:僵尸进程amp;孤儿进程,蓝瘦香菇

    进程 先来说下什么是进程: 来看下百度是怎么说的: 光看说的不够形象,在windows系统中,它长这样: 在Mac系统中,它长这样: Linux中是这样的:(有点长截图一部分好了) [root@iz2 ...

最新文章

  1. 为什么 MySQL 的自增主键不单调也不连续
  2. JavaScript之事件的绑定与移除
  3. Chapter 1 First Sight——17
  4. 十三、Tomcat的WebSocket支持
  5. 一行命令搭建内部的管道
  6. Java开发必会Git分布式版本控制系统实战篇
  7. 解密GaussDB(for Influx)时序洞察
  8. 【Es】es 无法启动 报错 Elasticsearch.init Bootstrap.setup OsProbe NullPointException
  9. mysql逻辑读高影响_运维日记| MySQL/Oracle深度解析之一:逻辑读
  10. 【SVN】SVN 的使用新手指南,具体到步骤详细介绍----TortoiseSVN
  11. 从入门到精通进阶篇 - 设置负载阶梯式压测场景(详解教程)
  12. 【渗透测试实战】PHP语言有哪些后门?以及利用方法
  13. odp.net连接oracle9i 出错解决_交换机常见故障及解决方法
  14. python安装失败错误代码0x_详解雨林木风Win10提示“Python 0x80070643安装时发生严重错误”解决方法...
  15. 西安电子科技大学计算机学院数据结构真题,数据结构1800题(标准答案全)
  16. php laypage 开发demo,laypage+laytpl示例
  17. php怎么看回调的异步通知的数据_paypal支付,异步回调(php)
  18. DES 加密解密的通俗易懂
  19. 把Excel批注的“红三角”放在单元格左上角_excel批注的玩法,看看你会几个
  20. 微信小程序服务器被ddos攻击,网站被DDOS攻击了怎么办

热门文章

  1. jQuery触发 a 标签点击事件
  2. Access中创建含有OLE对象列的表
  3. 亚马逊美国站物流成本上涨
  4. 自我介绍——当年毕业生版本
  5. 每个女孩心中都有一个宋思明(少儿不宜) - 读《蜗居》有感
  6. 解锁scrapy报错:Unknown command: crawl
  7. springboot根据模板导出word
  8. MSS与MTU的关系
  9. a标签之target属性----在何处打开链接
  10. yahoo pop3设置方法