如何停止“不间断” Linux 上的进程?

发布于 2024-07-18 01:52:52 字数 262 浏览 16 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

回眸一笑 2024-07-25 01:52:52

简单的回答:你不能。

更长的答案:不间断睡眠意味着进程不会被信号唤醒。 它只能被它正在等待的东西唤醒。 当我遇到这样的情况时,例如。 使用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.

梦归所梦 2024-07-25 01:52:52

杀死一个不间断的进程会成功,但它不会立即执行。 该进程在实际接收到信号之前不会消失。 所以仅仅发送信号不足以摆脱该进程,你还必须将其从不间断睡眠中唤醒。

Tanel Poder 写了一篇很棒的 D 状态流程分析指南。 这种状态很典型是由不完整的 I/O 引起的,例如网络故障。 slm 发布了一些关于超级用户如何解除网络 I/O 堵塞以及问题本身的非常有用的指示。

就我个人而言,在 VirtualBox 上处理 Windows 时,甚至使用 wine 时,我经常遇到这个问题,因为 cdrom I/O 永远不会完成(我猜它是某种光盘存在检查)。 ATA 设备可以重置,可能会解除该过程的阻塞。 例如,我使用以下小脚本来重置我的两个光驱,解除它们阻塞的进程:

echo 1 > /sys/block/sr0/delete
echo 1 > /sys/block/sr1/delete
echo "- - -" > /sys/class/scsi_host/host7/scan

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:

echo 1 > /sys/block/sr0/delete
echo 1 > /sys/block/sr1/delete
echo "- - -" > /sys/class/scsi_host/host7/scan
明媚如初 2024-07-25 01:52:52

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).

爱冒险 2024-07-25 01:52:52

我最近在远程服务器上遇到了一个处于 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.

╰◇生如夏花灿烂 2024-07-25 01:52:52

正如其他人所说,不可中断进程是一个卡在内核函数中且不能被中断的进程(通常它正在等待某些 I/O 操作)。 有关详细说明,请参阅此答案

除了重新启动计算机之外,我还通过刷新linux VM成功地将一些进程从D状态中带出来缓存

kill -9 {process_id}
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches

这似乎不会影响系统稳定性,但我不是系统程序员,不确定这可能会产生什么意想不到的后果。


编辑

根据内核文档 , drop_caches 在开发环境中似乎相当安全。

drop_caches

写入此内容将导致内核删除干净的缓存,以及
可回收的平板对象,例如目录和索引节点。 一旦掉落,他们的
内存变得空闲。

释放页面缓存:

回声1>   /proc/sys/vm/drop_caches 
  

释放可回收的slab对象(包括dentry和inode):

回声2>   /proc/sys/vm/drop_caches 
  

释放slab对象和页面缓存:

echo 3>   /proc/sys/vm/drop_caches 
  

这是一个非破坏性操作,不会释放任何脏对象。
要增加此操作释放的对象数量,用户可以运行
在写入 /proc/sys/vm/drop_caches 之前进行“同步”。 这将最大限度地减少
系统上脏对象的数量并创建更多候选对象
掉落。

该文件不是控制各种内核缓存增长的手段
(索引节点、目录项、页面缓存等...)这些对象会自动
当系统其他地方需要内存时,由内核回收。

使用此文件可能会导致性能问题。 因为它会丢弃缓存
对象,可能会花费大量的 I/O 和 CPU 来重新创建对象
掉落的物体,尤其是在大量使用的情况下。 因为这,
不建议在测试或调试环境之外使用。

当此文件被打开时,您可能会在内核日志中看到信息性消息
使用:

cat (1234): drop_caches: 3 
  

这些仅供参考。 他们并不意味着有什么问题
与您的系统。 要禁用它们,请将 4(位 3)回显到 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:

kill -9 {process_id}
sync
echo 3 | sudo tee /proc/sys/vm/drop_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.

drop_caches

Writing to this will cause the kernel to drop clean caches, as well as
reclaimable slab objects like dentries and inodes. Once dropped, their
memory becomes free.

To free pagecache:

echo 1 > /proc/sys/vm/drop_caches

To free reclaimable slab objects (includes dentries and inodes):

echo 2 > /proc/sys/vm/drop_caches

To free slab objects and pagecache:

echo 3 > /proc/sys/vm/drop_caches

This is a non-destructive operation and will not free any dirty objects.
To increase the number of objects freed by this operation, the user may run
`sync' prior to writing to /proc/sys/vm/drop_caches. This will minimize the
number of dirty objects on the system and create more candidates to be
dropped.

This file is not a means to control the growth of the various kernel caches
(inodes, dentries, pagecache, etc...) These objects are automatically
reclaimed by the kernel when memory is needed elsewhere on the system.

Use of this file can cause performance problems. Since it discards cached
objects, it may cost a significant amount of I/O and CPU to recreate the
dropped objects, especially if they were under heavy use. Because of this,
use outside of a testing or debugging environment is not recommended.

You may see informational messages in your kernel log when this file is
used:

cat (1234): drop_caches: 3

These are informational only. They do not mean that anything is wrong
with your system. To disable them, echo 4 (bit 3) into drop_caches.

_蜘蛛 2024-07-25 01:52:52

新来的,经验不足,但我遇到了同样的问题,当我使用 htop 检查进程的状态时,我可以看到我的进程进入不间断睡眠(D 状态)。
由于某种原因,

kill -9 <pid>

为我工作。 也许你也可以尝试一下。

编辑:详细的答案是 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,

kill -9 <pid>

worked for me. Maybe you can try the same.

Edit: the detailed answer is up there by ostrokach (which I didn't see).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文