How to kill defunct process(Linux如何杀死defunct进程)

本文介绍如何识别和处理系统中出现的僵尸进程,这些进程通常源于应用缺陷或用户异常操作,会导致资源浪费。文中提供了检查僵尸进程的命令行方法,并探讨了重启计算机和使用特定命令进行清理的两种解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Defunct processes are corrupted processes that can no longer communicate between the parent and child one. Sometimes, they become “zombies” and remain in your system until you reboot your machine. You can try to apply “kill -9” command, but most of the time you’ll be out of luck.

In order to kill theses defunct processes, you have two choices:
1. Reboot your computer
2. Continue reading…

First, let’s find out if the system contains defunct process:

$ ps -A | grep defunct

Assume your output is as the following:


8328 ? 00:00:00 mono <defunct>
8522 ? 00:00:01 mono <defunct>
13132 ? 00:00:00 mono <defunct>
25822 ? 00:00:00 ruby <defunct>
28383 ? 00:00:00 ruby <defunct>
18803 ? 00:00:00 ruby <defunct>

This means you have 6 defunct processes: 3 of mono, and 3 of ruby. These processes exists because of poorly written application or unusual action taken by the user, in my case there must be some serious problem with the program I wrote in mono C# 

### 如何在Linux中终止子进程 当遇到无法通过常规方式杀死的子进程时,可以尝试以下几种方法来解决问题。 #### 方法一:使用`killall` 对于特定命令启动的多个实例或难以定位确切PID的情况,`killall`是一个有效的工具。此命令可以根据名称终止所有匹配的进程[^2]: ```bash killall -9 <command_name> ``` 这会向名为 `<command_name>` 的所有进程发送 SIGKILL 信号(-9),强制它们立即停止运行。 #### 方法二:处理僵尸进程 如果面对的是已经变成僵尸状态(defunct)的子进程,则需要先结束其父进程。因为只有父进程退出后,init 进程(通常为 PID=1)才会接管并清理这些孤儿进程[^3]: ```bash ps aux | grep '<parent_process>' kill -TERM <parent_pid> # 尝试优雅关闭 # 或者更激进的方式 kill -KILL <parent_pid> ``` 注意,在采取上述措施前应当确认不会影响其他依赖于该父进程的服务或功能。 #### 方法三:利用`pkill`按模式匹配查找目标 相比直接指定完整的命令名而言,有时仅知道部分字符串就足以识别待终结的目标。此时可借助 `pkill` 命令实现模糊查询与批量操作: ```bash pkill -f 'part_of_command_line' ``` 这里的 `-f` 参数允许 pkill 查找整个命令行而非仅仅是程序文件路径中的片段. #### 方法四:检查权限问题 考虑到并非 root 用户可能缺乏足够的权利执行某些敏感指令,建议临时提升当前shell环境下的特权级别再重试前述任一方案: ```bash sudo su - # 执行相应的 kill/killall/pkill 操作... exit ``` 这样做可以在不影响系统安全性的前提下获得必要的控制权去管理那些顽固的后台任务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值