我刚刚注意到 CentOS 6.8(Final) 上的一些僵尸进程,试图杀死它们,但它们仍然存在:
[root@host user]# ps -ef | grep git
tomcat 746 1 0 Jul18 ? 00:00:00 git clone https://github.com/angular/bower-angular.git -b v1.3.20 --progress . --depth 1
tomcat 747 746 0 Jul18 ? 00:00:00 [git-remote-http] <defunct>
root 20776 20669 0 09:03 pts/3 00:00:00 grep git
tomcat 29970 1 0 Jul18 ? 00:00:00 git clone https://github.com/components/jqueryui.git -b 1.12.0 --progress . --depth 1
tomcat 29971 29970 0 Jul18 ? 00:00:00 [git-remote-http] <defunct>
[root@host user]# kill 746 747 29970 29971
[root@host user]# ps -ef | grep git
tomcat 746 1 0 Jul18 ? 00:00:00 git clone https://github.com/angular/bower-angular.git -b v1.3.20 --progress . --depth 1
tomcat 747 746 0 Jul18 ? 00:00:00 [git-remote-http] <defunct>
root 21525 20669 0 09:26 pts/3 00:00:00 grep git
tomcat 29970 1 0 Jul18 ? 00:00:00 git clone https://github.com/components/jqueryui.git -b 1.12.0 --progress . --depth 1
tomcat 29971 29970 0 Jul18 ? 00:00:00 [git-remote-http] <defunct>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它们已经运行了两个月,而且如果它们无害,我会摆脱它们,还有其他杀死僵尸的方法吗?
hee*_*ayl 40
你不能杀死一个僵尸(进程),它已经死了。它只是等待其父进程执行wait(2)
并收集其退出状态。除了进程表条目之外,它不会占用系统上的任何资源。
您可以发送SIGCHLD
给它的父级,让它知道它的一个子级已经终止(即请求它收集子级的退出状态)。可以忽略此信号(这是默认设置):
kill -CHLD <PPID>
Run Code Online (Sandbox Code Playgroud)
(替换<PPID>
为父级的实际 PID。)
或者,您可以终止父进程,以便init
(PID 1) 继承僵尸进程并正确获取它(init
继承任何孤儿并wait(2)
定期执行是 的主要任务之一)。但是不建议杀死父级。通常,僵尸进程的创建表示编程问题/问题,您应该尝试修复或报告该问题。
正如 Heemayl 所提到的,你实际上无法杀死僵尸。它已经[un]死了......
但是,您面临的问题看起来像是git clone
命令的问题。它以某种方式卡住了。可能超时或以其他方式失败?通常是因为某些 I/O 导致进程卡在 aSIGTERM
和SIGINT
无法工作的地步。
要杀死它,在这种情况下,您需要使用-9
命令行选项。这意味着发送SIGKILL
信号。你也可以实际使用-KILL
。
[root@host user]# kill -KILL 746 29970
Run Code Online (Sandbox Code Playgroud)
要获取可用信号的列表,请使用 list 命令行选项。
[root@host user]# kill -l
Run Code Online (Sandbox Code Playgroud)
这会显示数字和名称(您会看到 #9 表示 SIGKILL。)