僵尸进程 [英] Zombie processes

查看:127
本文介绍了僵尸进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我心中已经对僵尸进程的一些问题

I'v some questions about zombie processes


  • 从什么僵尸进程概念的好处?

  • 知道内核维护(PID,终止状态,资源使用信息)的僵尸进程结果
    什么是的资源使用信息
  • 的意义
  • 僵尸的PPID()如何= 1,它仍然僵尸(INIT收割植物大战僵尸,因为它等待()默认情况下)结果
    任何一个可以写的一些C code 的制作僵尸它的父是初始化?

  • 可以拒绝僵尸来释放内存的一些锁?

  • what the benefits from zombie process concept?
  • know that the kernel keeps (PID,termination status, resource usage information) for zombie process
    what's the meaning of "resource usage information"
  • how zombie's PPID() = 1 and it still zombie , (init reaps Zombies because it wait() by default)
    can any one write some C code to make a zombie it's parent is Init?
  • can zombies refusing to release some lock on memory??

在此先感谢

推荐答案

- ?从什么僵尸进程概念的好处

-- what the benefits from zombie process concept?

一个僵尸进程就是一个pid,退出状态,而且总是在那里,直到家长使用的一个部分会计信息的家庭系统调用来获取其最终状态。直到家长来电孩子的进程ID必须保持标记为已使用,这样没有其他进程可以分配它。如果另一个进程均获得分配一个再生的pid这将是很难说具有该相同PID它和previous过程之间的差异。一旦由父调用,并返回一个最终的退出状态,可以设想,没有人会去寻找那个再次PID孩子,所以PID现在可能重复使用。
(我想在Linux上,如果父母离开SIGCHLD SIG_IGN作为内核将不会保持周围的僵尸,但重新注册SIGCHLD的配置为SIG_IGN不会有同样的效果)

A zombie process is just a pid, an exit status, and some accounting information that stays around until a parent uses one of the wait family of system calls to get its final status. Until a parent calls wait the child's process ID must stay marked as used so that no other process can be assigned it. If another process were to get assigned a recycled pid it would be difficult to tell the difference between it and previous processes that had that same pid. Once wait is called by the parent and returns a final exit status it can be assumed that no one will go looking for the child at that pid again, so the pid may now be reused. (I think on Linux if a parent leaves SIGCHLD as SIG_IGN the kernel will not keep zombies around, but that re-registering SIGCHLD's disposition as SIG_IGN does not have the same effect)

- 知道内核维护(PID,终止状态,资源使用信息)的僵尸进程什么的资源使用信息

-- know that the kernel keeps (PID,termination status, resource usage information) for zombie process what's the meaning of "resource usage information"

有些信息是运行的程序为:

Some of this information is what running a program as:

time my_program

将报告。这些值通常在SIGINFO结构SIGCHLD报道(这是不完全以呼叫等待),但也可以从在 waitid通话 systme调用(在某些系统上)的形式。看看男人的sigaction 有关这个结构的信息。

will report. These values are usually reported in the siginfo structure for SIGCHLD (which isn't exactly a call to wait) but also available from a call to the waitid form of systme call (on some systems). Look at man sigaction for info about this structure.

- 僵尸的PPID()如何= 1,它仍然僵尸(INIT收割植物大战僵尸,因为它等待()默认情况下)

-- how zombie's PPID() = 1 and it still zombie , (init reaps Zombies because it wait() by default)

一个僵尸的PPID = 1应该不留一具僵尸很长,因为的的init 的收获应该很快pretty。一个进程将继续从它死亡后不久,一个点一个僵尸,直到其父电话(通过退出通过杀死它的unhanded信号或)等待,并得到它的最终状态。这意味着,即使init却只是调用初始化一遍又一遍地有可能是少量时间,其中的过程可能会显示为一个僵尸。如果进程显示为子女的的init 的(0 = PPID)长期大量的时间(秒),那么就有可能是错误的。

A zombie whose ppid = 1 should not stay a zombie for very long because init should reap it pretty quickly. A process will remain a zombie from a point soon after it dies (either via exit or by an unhanded signal that kills it) until its parent calls wait and gets it's final status. This means that even if init does nothing but call init over and over there could be a small amount of time where a process may show up as a zombie. If processes show up as children of init (0=ppid) for long amounts of time (seconds) then something is probably wrong.

- ?任何一个可以写一些C code键使僵尸它的父是初始化

-- can any one write some C code to make a zombie it's parent is Init?

这是不明确的,但我觉得你想要的:

This isn't clear, but I think you want:

pid_t f = fork();
if (f > 0) {
    exit(0); // this is the parent dying, so the child will be an orphan
             // and get adopted by init
} else if (f == 0) {
    sleep(100); // This is the child doing something that takes enough time for
                // its parent to commit suicide (exit(0)) and then for you to
                // observe that it has now been adopted by init
    exit(0);    // And now it dyes as well, so init should reap its status, but
                // it may be a zombie for a short amount of time first.
} else /* error condition would be handled here */

- 僵尸可以拒绝释放内存的一些锁?

-- can zombies refusing to release some lock on memory??

僵尸摆脱不了太多东西。他们失去了所有的内存页,打开的文件句柄,...等等。 pretty所有事情操作系统可以弄清楚如何释放应该得到释放。这将是一个错误不,但请记住,操作系统必须知道它是什么,是应该被释放。这是很容易当一个程序死亡,该操作系统不知道是应该被释放,以创建在用户空间资源应该被释放。

Zombies can't hold onto much of anything. They lose all of their memory pages, open file handles, ...etc. Pretty much everything the operating system can figure out how to free up should get freed. It would be a bug not to, but remember that the OS has to know that it is something that is supposed to be freed. It is very easy to create resources in user space that should be freed when a program dies that the OS doesn't know are supposed to be freed.

这篇关于僵尸进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆