如何停止“不间断” Linux 上的进程?
我有一个 VirtualBox 进程挂在它周围,我试图杀死它(KILL
/ABORT
),但没有成功。 父进程 pid 为 1(init)。
top
将进程显示为 D
,其记录为“不间断睡眠”。
strace
什么也没显示。
我怎样才能摆脱这个? 它阻止我卸载 VirtualBox 内核驱动程序以加载更新的驱动程序。
I have a VirtualBox process hanging around which I tried to kill (KILL
/ABORT
) but without success. The parent pid is 1 (init).
top
shows the process as D
which is documented as "uninterruptible sleep".
strace
shows up nothing.
How can I get rid of this? It prevents me from unloading the VirtualBox kernel driver to load a newer one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
简单的回答:你不能。
更长的答案:不间断睡眠意味着进程不会被信号唤醒。 它只能被它正在等待的东西唤醒。 当我遇到这样的情况时,例如。 使用CD-ROM时,我通常使用挂起到磁盘和恢复来重置计算机。
Simple answer: you cannot.
Longer answer: the uninterruptable sleep means the process will not be woken up by signals. It can be only woken up by what it's waiting for. When I get such situations eg. with CD-ROM, I usually reset the computer by using suspend-to-disk and resuming.
杀死一个不间断的进程会成功,但它不会立即执行。 该进程在实际接收到信号之前不会消失。 所以仅仅发送信号不足以摆脱该进程,你还必须将其从不间断睡眠中唤醒。
Tanel Poder 写了一篇很棒的 D 状态流程分析指南。 这种状态很典型是由不完整的 I/O 引起的,例如网络故障。 slm 发布了一些关于超级用户如何解除网络 I/O 堵塞以及问题本身的非常有用的指示。
就我个人而言,在 VirtualBox 上处理 Windows 时,甚至使用 wine 时,我经常遇到这个问题,因为 cdrom I/O 永远不会完成(我猜它是某种光盘存在检查)。 ATA 设备可以重置,可能会解除该过程的阻塞。 例如,我使用以下小脚本来重置我的两个光驱,解除它们阻塞的进程:
Killing an uninterruptible process succeeds, it just doesn't do so immediately. The process won't disappear until it actually receives the signal. So sending a signal alone is not enough to get rid of the process, you also have to wake it up from uninterruptible sleep.
Tanel Poder has written a great guide to analyse D state processes. It is very typical that this state is caused by incomplete I/O, e.g. network failure. slm has posted some very useful pointers on superuser how to unjam the network I/O, and also about the problem itself.
Personally, when dealing with Windows on VirtualBox, and even with wine, I often run into this problem because of a cdrom I/O that never completes (I guess its some sort of disc presence check). ATA devices can be reset, which likely will unjam the process. For instance, I'm using the following little script to reset both my optical drives, unjamming the processes they are blocking:
D状态基本上意味着进程正在等待磁盘I/O,或者其他不能被中断的块I/O。 有时这意味着内核或设备正在疯狂地尝试读取坏块(尤其是从光盘)。 有时这意味着还有其他事情。
该进程在退出 D 状态之前无法被终止。 找出它正在等待什么并解决它。 最简单的方法是重新启动。 有时删除有问题的磁盘会有所帮助,但这可能相当危险:如果您不知道自己在做什么,则会出现无法修复的灾难性硬件故障(请阅读:冒烟)。
The D state basically means that the process is waiting for disk I/O, or other block I/O that can't be interrupted. Sometimes this means the kernel or device is feverishly trying to read a bad block (especially from an optical disk). Sometimes it means there's something else.
The process cannot be killed until it gets out of the D state. Find out what it is waiting for and fix that. The easy way is to reboot. Sometimes removing the disk in question helps, but that can be rather dangerous: unfixable catastrophic hardware failure if you don't know what you're doing (read: smoke coming out).
我最近在远程服务器上遇到了一个处于
D
状态的进程,我想澄清一下,需要硬重启或重新启动电源才能删除该进程。在用尽所有其他选项之前,请勿尝试软重启。 例如,您可以尝试释放进程所占用的任何资源。 软重启可能会让您的系统部分关闭并且不再响应 ssh,但不会重新启动,因为它挂起并试图终止不可中断的进程。
I recently encountered a process in
D
state on a remote server and would like to clarify that a hard reboot or power cycle is needed to remove the process.Don't try a soft reboot until you have exhausted all other options. For example, you can try freeing up whatever resource the process is hanging on. A soft reboot might give you a system that is partially shut down and will no longer respond to ssh, but won't reboot because it is hung trying to terminate the uninterruptible process.
正如其他人所说,不可中断进程是一个卡在内核函数中且不能被中断的进程(通常它正在等待某些 I/O 操作)。 有关详细说明,请参阅此答案。
除了重新启动计算机之外,我还通过刷新linux VM成功地将一些进程从
D
状态中带出来缓存:这似乎不会影响系统稳定性,但我不是系统程序员,不确定这可能会产生什么意想不到的后果。
编辑:
根据内核文档 ,
drop_caches
在开发环境中似乎相当安全。As others have said, an uninterruptable process is a process which is stuck in a kernel function which cannot be interrupted (usually it is waiting for some I/O operation). See this answer for a detailed description.
Apart from restarting the computer, I had success bringing some processes out of the
D
state by flushing linux VM caches:This did not seem to affect system stability, but I'm not a systems programmer and not sure what unintended consequences this might have.
Edit:
According to the kernel docs,
drop_caches
appears to be reasonably safe in a development environment.新来的,经验不足,但我遇到了同样的问题,当我使用 htop 检查进程的状态时,我可以看到我的进程进入不间断睡眠(D 状态)。
由于某种原因,
为我工作。 也许你也可以尝试一下。
编辑:详细的答案是 ostrokach 的(我没有看到)。
new here and not that experienced, but I had the same issue where I could see my processes going into uninterruptible sleep (D state) when I checked their status using htop.
For some reason,
worked for me. Maybe you can try the same.
Edit: the detailed answer is up there by ostrokach (which I didn't see).