2

在我的服务器机器中,每天都有一些进程进入失效状态。它会影响我的 CPU 使用率。需要编写一个shell脚本来杀死已失效的进程ID和父ID。

例如,当我运行命令时:

ps -ef|grep defunct.

找到可能的值。在那我只需要杀死“[chrome] defunct”进程。

样本条目:-

bitnami  12217 12111  0 Feb09 pts/3    00:00:00 [chrome] <defunct>

我需要杀死这种类型的 chrome 条目。任何人都可以建议一些样本来杀死条目

4

2 回答 2

4

Defunct processes do not go away until the parent process collects the corpse or the parent dies. When the parent process dies, the defunct processes are inherited by PID 1 (classically it is PID 1; it is some system process designated with the job), and PID 1 is designed to wait for dead bodies and remove them from the process table. So, strictly, the defunct processes only go away when their parent collects the corpse; when the original parent dies, the new parent collects the corpse so the defunct process goes away at last.

So, either write the parent code so that it waits on its dead children, or kill the parent process.

Note that defunct processes occupy very little resources - basically, a slot in the process table and the resource (timing) information that the parent can ask for. Having said that, last year I was working on a machine where there were 3 new defunct processes per minute, owned by a a system process other than PID 1, that were not being harvested. Things like ps took a long, long, long time when the number of defunct processes climbed into the hundreds of thousands. (The solution was to install the correct fix pack for the o/s.) They are not completely harmless, but a few are not a major problem.

于 2012-02-10T07:44:24.470 回答
2

它已经死了。父母需要收获它,然后它就会消失。

于 2012-02-10T06:26:52.690 回答