什么是不间断进程? [英] What is an uninterruptible process?

查看:64
本文介绍了什么是不间断进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时每当我在 Linux 中编写程序并由于某种错误而崩溃时,它会变成一个不可中断的进程并一直运行直到我重新启动计算机(即使我退出).我的问题是:

Sometimes whenever I write a program in Linux and it crashes due to a bug of some sort, it will become an uninterruptible process and continue running forever until I restart my computer (even if I log out). My questions are:

  • 是什么导致流程变得不可中断?
  • 我该如何阻止这种情况发生?
  • 这可能是一个愚蠢的问题,但有没有办法在不重新启动计算机的情况下中断它?

推荐答案

不可中断进程是恰好处于系统调用(内核函数)中且不能被信号中断的进程.

An uninterruptible process is a process which happens to be in a system call (kernel function) that cannot be interrupted by a signal.

要理解这意味着什么,您需要了解可中断系统调用的概念.经典的例子是read().这是一个可能需要很长时间(几秒钟)的系统调用,因为它可能涉及启动硬盘驱动器或移动磁头.在这段时间的大部分时间里,该进程将处于休眠状态,并在硬件上阻塞.

To understand what that means, you need to understand the concept of an interruptible system call. The classic example is read(). This is a system call that can take a long time (seconds) since it can potentially involve spinning up a hard drive, or moving heads. During most of this time, the process will be sleeping, blocking on the hardware.

当进程在系统调用中休眠时,它可以接收到 Unix 异步信号(比如 SIGTERM),然后发生以下情况:

While the process is sleeping in the system call, it can receive a Unix asynchronous signal (say, SIGTERM), then the following happens:

  • 系统调用提前退出,并设置为将 -EINTR 返回到用户空间.
  • 执行信号处理程序.
  • 如果进程仍在运行,它会从系统调用中获取返回值,并且可以再次进行相同的调用.

从系统调用中提前返回使用户空间代码能够立即改变其响应信号的行为.例如,干净地终止以响应 SIGINT 或 SIGTERM.

Returning early from the system call enables the user space code to immediately alter its behavior in response to the signal. For example, terminating cleanly in reaction to SIGINT or SIGTERM.

另一方面,有些系统调用是不允许以这种方式中断的.如果系统调用由于某种原因停止,该进程可以无限期地保持在这种不可终止状态.

On the other hand, some system calls are not allowed to be interrupted in this way. If the system calls stalls for some reason, the process can indefinitely remains in this unkillable state.

LWN 在 7 月发表了一篇好文章,触及了这个话题.

LWN ran a nice article that touched this topic in July.

回答原来的问题:

  • 如何防止这种情况发生:找出导致您出现问题的驱动程序,然后停止使用,或者成为内核黑客并修复它.

  • How to prevent this from happening: figure out which driver is causing you trouble, and either stop using, or become a kernel hacker and fix it.

如何在不重启的情况下终止不可中断的进程:以某种方式使系统调用终止.通常,在不按电源开关的情况下执行此操作的最有效方法是拉电源线.您还可以成为内核黑客并让驱动程序使用 TASK_KILLABLE,如 LWN 文章中所述.

How to kill an uninterruptible process without rebooting: somehow make the system call terminate. Frequently the most effective manner to do this without hitting the power switch is to pull the power cord. You can also become a kernel hacker and make the driver use TASK_KILLABLE, as explained in the LWN article.

这篇关于什么是不间断进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆