如何通过 shell 脚本杀死 linux defunct 进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9223608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to kill linux defunct process by shell script
提问by Mohan Shanmugam
In my server machines some process goes to defunct state for every day. it affects my CPU usage. Need to write a shell script to kill the defunct process id and parent id.
在我的服务器机器中,每天都有一些进程进入失效状态。它会影响我的 CPU 使用率。需要编写一个shell脚本来杀死已失效的进程id和父id。
For example, when i run the command:
例如,当我运行命令时:
ps -ef|grep defunct.
found may values. In that i need to kill only "[chrome] defunct" process.
发现可能值。因为我只需要杀死“[chrome] defunct”进程。
sample entry:-
样本条目:-
bitnami 12217 12111 0 Feb09 pts/3 00:00:00 [chrome] <defunct>
I need to kill this type of chrome entries. Can any one suggest some samples to kill the entries
我需要杀死这种类型的 chrome 条目。任何人都可以建议一些样本来杀死条目
回答by Ignacio Vazquez-Abrams
It's already dead. The parent needs to reap it and then it will go away.
它已经死了。父母需要收获它,然后它就会消失。
回答by Jonathan Leffler
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.
在父进程收集尸体或父进程死亡之前,失效的进程不会消失。当父进程死亡时,已失效的进程由 PID 1 继承(通常它是 PID 1;它是一些指定了作业的系统进程),而 PID 1 旨在等待死体并将它们从进程表中删除。因此,严格来说,失效的进程只有在其父收集尸体时才会消失;当原来的父母去世时,新的父母会收集尸体,因此死掉的过程最终消失了。
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.
请注意,已失效的进程占用的资源非常少——基本上,进程表中的一个插槽和父进程可以请求的资源(时间)信息。话虽如此,去年我在一台机器上工作,每分钟有 3 个新的失效进程,由除 PID 1 以外的系统进程拥有,这些进程没有被收集。ps
当失效进程的数量攀升到数十万时,事情花了很长时间。(解决方案是为 o/s 安装正确的修订包。)它们并非完全无害,但有一些不是主要问题。