What are Zombies and what causes them? Are there Zombie processes and Zombie objects?

后端 未结 2 1349
名媛妹妹
名媛妹妹 2020-12-13 18:12

I can find questions about zombies but none that directly addresses what they are and why and how they occur. There are a couple that address what zombie processes are in th

2条回答
  •  死守一世寂寞
    2020-12-13 18:57

    When a process ends, much of its state still exists in the kernel, because its parent may still want to look at a few things, like its return value, which needs to be stored someplace. When a parent calls wait() or waitpid(), it tells the kernel to throw it all away because it's done with it. Until it does so, the child retains a pid and uses up resources. Those un-reaped child processes are called zombies. Even killing a zombie won't remove it, it must be reaped (wait-ed-upon) by its parent. If the parent dies, they are passed to "init" on unix systems, whose sole job is to wait for things to clean them up.

    I've never heard of "zombie objects", but I assume that it refers to things that have either not been cleaned up by the garbage collector, or that have circular references or some such thing, such that they are not going to be cleaned up by the garbage collector. The metaphor is pretty similar: fork()==malloc(), wait()==free() at a certain level. (Not a perfect metaphor, of course.)

提交回复
热议问题