System Hangs-程序员宅基地

技术标签: linux  

System Hangs

Although most bugs in kernel code end up as oops messages, sometimes they can completely hang the system. If the system hangs, no message is printed. For example, if the code enters an endless loop, the kernel stops scheduling,[3] and the system doesn't respond to any action, including the magic Ctrl-Alt-Del combination. You have two choices for dealing with system hangs—either prevent them beforehand or be able to debug them after the fact. 尽管大多数内核代码中的bug最后都变成了 "哎呀 "信息,但有时它们会使系统完全挂起。如果系统挂起,就不会有任何信息被打印出来。例如,如果代码进入了一个无休止的循环,内核就会停止调度,[3] 而且系统对任何操作都没有反应,包括神奇的Ctrl-Alt-Del组合。在处理系统挂起时,你有两个选择--要么事先防止它们,要么事后能够调试它们。

You can prevent an endless loop by inserting schedule invocations at strategic points. The schedule call (as you might guess) invokes the scheduler and, therefore, allows other processes to steal CPU time from the current process. If a process is looping in kernel space due to a bug in your driver, the schedule calls enable you to kill the process after tracing what is happening. 你可以通过在战略点插入schedule调用来防止无休止的循环。schedule调用(正如你可能猜到的那样)会调用调度程序,因此,允许其他进程从当前进程中窃取CPU时间。如果一个进程由于你的驱动程序中的一个错误而在内核空间中循环,schedule调用可以使你在追踪正在发生的事情后杀死该进程。

You should be aware, of course, that any call to schedule may create an additional source of reentrant calls to your driver, since it allows other processes to run. This reentrancy should not normally be a problem, assuming that you have used suitable locking in your driver. Be sure, however, not to call schedule any time that your driver is holding a spinlock. 当然,你应该意识到,任何对schedule的调用都可能给你的驱动程序创造一个额外的可重入调用源,因为它允许其他进程运行。假设你在你的驱动程序中使用了合适的锁,这种可重入性通常不应该是一个问题。然而,请确保不要在你的驱动程序持有自旋锁的时候调用schedule。

If your driver really hangs the system, and you don't know where to insert schedule calls, the best way to go may be to add some print messages and write them to the console (by changing the console_loglevel value if need be). 如果你的驱动程序真的挂起了系统,而你又不知道在哪里插入schedule调用,最好的办法可能是增加一些打印信息,并把它们写到控制台(如果需要的话,通过改变console_loglevel值)。

Sometimes the system may appear to be hung, but it isn't. This can happen, for example, if the keyboard remains locked in some strange way. These false hangs can be detected by looking at the output of a program you keep running for just this purpose. A clock or system load meter on your display is a good status monitor; as long as it continues to update, the scheduler is working. 有时,系统可能看起来是挂起的,但其实不是。例如,如果键盘以某种奇怪的方式被锁定,就会发生这种情况。这些错误的挂起可以通过查看你为这个目的而运行的程序的输出来检测。你显示屏上的时钟或系统负载表是一个很好的状态监测器;只要它持续更新,调度器就在工作。

An indispensable tool for many lockups is the "magic SysRq key," which is available on most architectures. Magic SysRq is invoked with the combination of the Alt and SysRq keys on the PC keyboard, or with other special keys on other platforms (see Documentation/sysrq.txt for details), and is available on the serial console as well. A third key, pressed along with these two, performs one of a number of useful actions: 对于许多锁定来说,一个不可缺少的工具是 "Magic SysRq键",它在大多数架构上都可用。魔术SysRq是通过PC键盘上的Alt和SysRq键的组合来调用的,或者在其他平台上通过其他特殊键来调用(详见文档/sysrq.txt),并且在串行控制台中也可以使用。与这两个键同时按下的第三个键,可以执行一系列有用的操作之一。

r

Turns off keyboard raw mode; useful in situations where a crashed application (such as the X server) may have left your keyboard in a strange state. 关闭键盘原始模式;在一个崩溃的应用程序(如X服务器)可能使你的键盘处于一个奇怪的状态的情况下,非常有用。

k

Invokes the " secure attention key" (SAK) function. SAK kills all processes running on the current console, leaving you with a clean terminal. 调用 "安全注意键"(SAK)功能。SAK杀死所有在当前控制台运行的进程,给你留下一个干净的终端。

s

Performs an emergency synchronization of all disks. 对所有磁盘进行紧急同步。

u

Umount. Attempts to remount all disks in a read-only mode. This operation, usually invoked immediately after s, can save a lot of filesystem checking time in cases where the system is in serious trouble. Umount。试图以只读模式重新挂载所有磁盘。这个操作通常在s之后立即调用,在系统出现严重问题的情况下可以节省大量的文件系统检查时间。

b

Boot. Immediately reboots the system. Be sure to synchronize and remount the disks first. 启动。立即重新启动系统。请确保首先同步和重新安装磁盘。

p

Prints processor registers information. 打印处理器的寄存器信息。

t

Prints the current task list. 打印当前的任务列表。

m

Prints memory information. 打印内存信息

Other magic SysRq functions exist; see sysrq.txt in the Documentation directory of the kernel source for the full list. Note that magic SysRq must be explicitly enabled in the kernel configuration and that most distributions do not enable it, for obvious security reasons. For a system used to develop drivers, however, enabling magic SysRq is worth the trouble of building a new kernel in itself. Magic SysRq may be disabled at runtime with a command such as the following: 还有其他神奇的SysRq函数,完整的列表见内核源文件目录下的sysrq.txt。请注意,magic SysRq必须在内核配置中明确启用,大多数发行版都不启用它,这显然是出于安全考虑。然而,对于一个用于开发驱动程序的系统来说,启用magic SysRq本身就值得为构建一个新的内核而烦恼。Magic SysRq可以在运行时用如下命令来禁用。

echo 0 > /proc/sys/kernel/sysrq

You should consider disabling it if unprivileged users can reach your system keyboard, to prevent accidental or willing damages. Some previous kernel versions had sysrq disabled by default, so you needed to enable it at runtime by writing 1 to that same /proc/sys file. 如果没有特权的用户可以接触到你的系统键盘,你应该考虑禁用它,以防止意外或自愿的损害。一些以前的内核版本默认是禁用sysrq的,所以你需要在运行时通过在同一个/proc/sys文件中写1来启用它。

The sysrq operations are exceedingly useful, so they have been made available to system administrators who can't reach the console. The file /proc/sysrq-trigger is a write-only entry point, where you can trigger a specific sysrq action by writing the associated command character; you can then collect any output data from the kernel logs. This entry point to sysrq is always working, even if sysrq is disabled on the console. sysrq操作是非常有用的,所以它们被提供给那些无法到达控制台的系统管理员使用。文件/proc/sysrq-trigger是一个只写的入口点,在这里你可以通过写相关的命令字符来触发一个特定的sysrq操作;然后你可以从内核日志中收集任何输出数据。这个sysrq的入口点总是在工作,即使控制台的sysrq被禁用。

If you are experiencing a "live hang," in which your driver is stuck in a loop but the system as a whole is still functioning, there are a couple of techniques worth knowing. Often, the SysRq p function points the finger directly at the guilty routine. Failing that, you can also use the kernel profiling function. Build a kernel with profiling enabled, and boot it with profile=2 on the command line. Reset the profile counters with the readprofile utility, then send your driver into its loop. After a little while, use readprofile again to see where the kernel is spending its time. Another more advanced alternative is oprofile, that you may consider as well. The file Documentation/basic_profiling.txt tells you everything you need to know to get started with the profilers. 如果你遇到了 "live hang",即你的驱动程序被卡在一个循环中,但整个系统仍在运行,有几个技巧值得了解。通常,SysRq p函数可以直接指出有问题的程序。如果不这样做,你也可以使用内核profiling功能。建立一个启用了profiling功能的内核,并在命令行上用profile=2启动它。用readprofile工具重置profile计数器,然后把你的驱动程序送入它的循环。一段时间后,再次使用readprofile来查看内核在哪里花费时间。另一个更高级的选择是OPROFILE,你也可以考虑。Documentation/basic_profiling.txt文件告诉你开始使用profile所需要知道的一切。

One precaution worth using when chasing system hangs is to mount all your disks as read-only (or unmount them). If the disks are read-only or unmounted, there's no risk of damaging the filesystem or leaving it in an inconsistent state. Another possibility is using a computer that mounts all of its filesystems via NFS, the network file system. The "NFS-Root" capability must be enabled in the kernel, and special parameters must be passed at boot time. In this case, you'll avoid filesystem corruption without even resorting to SysRq, because filesystem coherence is managed by the NFS server, which is not brought down by your device driver. 当调查系统挂起时,一个值得使用的预防措施是将你所有的磁盘挂起为只读(或取消挂起)。如果磁盘是只读或未挂载的,就不会有损坏文件系统或使其处于不一致状态的风险。另一种可能性是使用一台通过NFS(网络文件系统)挂载其所有文件系统的计算机。必须在内核中启用 "NFS-Root "功能,并且在启动时必须传递特殊参数。在这种情况下,你会避免文件系统的损坏,甚至不需要借助SysRq,因为文件系统的一致性是由NFS服务器管理的,它不会被你的设备驱动程序所破坏。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/mounter625/article/details/132121913

智能推荐

软件测试流程包括哪些内容?测试方法有哪些?_测试过程管理中包含哪些过程-程序员宅基地

文章浏览阅读2.9k次,点赞8次,收藏14次。测试主要做什么?这完全都体现在测试流程中,同时测试流程是面试问题中出现频率最高的,这不仅是因为测试流程很重要,而是在面试过程中这短短的半小时到一个小时的时间,通过测试流程就可以判断出应聘者是否合适,故在测试流程中包含了测试工作的核心内容,例如需求分析,测试用例的设计,测试执行,缺陷等重要的过程。..._测试过程管理中包含哪些过程

政府数字化政务的人工智能与机器学习应用:如何提高政府工作效率-程序员宅基地

文章浏览阅读870次,点赞16次,收藏19次。1.背景介绍政府数字化政务是指政府利用数字技术、互联网、大数据、人工智能等新技术手段,对政府政务进行数字化改革,提高政府工作效率,提升政府服务质量的过程。随着人工智能(AI)和机器学习(ML)技术的快速发展,政府数字化政务中的人工智能与机器学习应用也逐渐成为政府改革的重要内容。政府数字化政务的人工智能与机器学习应用涉及多个领域,包括政策决策、政府服务、公共安全、社会治理等。在这些领域,人工...

ssm+mysql+微信小程序考研刷题平台_mysql刷题软件-程序员宅基地

文章浏览阅读219次,点赞2次,收藏4次。系统主要的用户为用户、管理员,他们的具体权限如下:用户:用户登录后可以对管理员上传的学习视频进行学习。用户可以选择题型进行练习。用户选择小程序提供的考研科目进行相关训练。用户可以进行水平测试,并且查看相关成绩用户可以进行错题集的整理管理员:管理员登录后可管理个人基本信息管理员登录后可管理个人基本信息管理员可以上传、发布考研的相关例题及其分析,并对题型进行管理管理员可以进行查看、搜索考研题目及错题情况。_mysql刷题软件

根据java代码描绘uml类图_Myeclipse8.5下JAVA代码导成UML类图-程序员宅基地

文章浏览阅读1.4k次。myelipse里有UML1和UML2两种方式,UML2功能更强大,但是两者生成过程差别不大1.建立Test工程,如下图,uml包存放uml类图package com.zz.domain;public class User {private int id;private String name;public int getId() {return id;}public void setId(int..._根据以下java代码画出类图

Flume自定义拦截器-程序员宅基地

文章浏览阅读174次。需求:一个topic包含很多个表信息,需要自动根据json字符串中的字段来写入到hive不同的表对应的路径中。发送到Kafka中的数据原本最外层原本没有pkDay和project,只有data和name。因为担心data里面会空值,所以根同事商量,让他们在最外层添加了project和pkDay字段。pkDay字段用于表的自动分区,proejct和name合起来用于自动拼接hive表的名称为 ..._flume拦截器自定义开发 kafka

java同时输入不同类型数据,Java Spring中同时访问多种不同数据库-程序员宅基地

文章浏览阅读380次。原标题:Java Spring中同时访问多种不同数据库 多样的工作要求,可以使用不同的工作方法,只要能获得结果,就不会徒劳。开发企业应用时我们常常遇到要同时访问多种不同数据库的问题,有时是必须把数据归档到某种数据仓库中,有时是要把数据变更推送到第三方数据库中。使用Spring框架时,使用单一数据库是非常容易的,但如果要同时访问多个数据库的话事件就变得复杂多了。本文以在Spring框架下开发一个Sp..._根据输入的不同连接不同的数据库

随便推点

EFT试验复位案例分析_eft电路图-程序员宅基地

文章浏览阅读3.6k次,点赞9次,收藏25次。本案例描述了晶振屏蔽以及开关电源变压器屏蔽对系统稳定工作的影响, 硬件设计时应考虑。_eft电路图

MR21更改价格_mr21 对于物料 zba89121 存在一个当前或未来标准价格-程序员宅基地

文章浏览阅读1.1k次。对于物料价格的更改,可以采取不同的手段:首先,我们来介绍MR21的方式。 需要说明的是,如果要对某一产品进行价格修改,必须满足的前提条件是: ■ 1、必须对价格生效的物料期间与对应会计期间进行开启; ■ 2、该产品在该物料期间未发生物料移动。执行MR21,例如更改物料1180051689的价格为20000元,系统提示“对于物料1180051689 存在一个当前或未来标准价格”,这是因为已经对该..._mr21 对于物料 zba89121 存在一个当前或未来标准价格

联想启天m420刷bios_联想启天M420台式机怎么装win7系统(完美解决usb)-程序员宅基地

文章浏览阅读7.4k次,点赞3次,收藏13次。[文章导读]联想启天M420是一款商用台式电脑,预装的是win10系统,用户还是喜欢win7系统,该台式机采用的intel 8代i5 8500CPU,在安装安装win7时有很多问题,在安装win7时要在BIOS中“关闭安全启动”和“开启兼容模式”,并且安装过程中usb不能使用,要采用联想win7新机型安装,且默认采用的uefi+gpt模式,要改成legacy+mbr引导,那么联想启天M420台式电..._启天m420刷bios

冗余数据一致性,到底如何保证?-程序员宅基地

文章浏览阅读2.7k次,点赞2次,收藏9次。一,为什么要冗余数据互联网数据量很大的业务场景,往往数据库需要进行水平切分来降低单库数据量。水平切分会有一个patition key,通过patition key的查询能..._保证冗余性

java 打包插件-程序员宅基地

文章浏览阅读88次。是时候闭环Java应用了 原创 2016-08-16 张开涛 你曾经因为部署/上线而痛苦吗?你曾经因为要去运维那改配置而烦恼吗?在我接触过的一些部署/上线方式中,曾碰到过以下一些问题:1、程序代码和依赖都是人工上传到服务器,不是通过工具进行部署和发布;2、目录结构没有规范,jar启动时通过-classpath任意指定;3、fat jar,把程序代码、配置文件和依赖jar都打包到一个jar中,改配置..._那么需要把上面的defaultjavatyperesolver类打包到插件中

VS2015,Microsoft Visual Studio 2005,SourceInsight4.0使用经验,Visual AssistX番茄助手的安装与基本使用9_番茄助手颜色-程序员宅基地

文章浏览阅读909次。1.得下载一个番茄插件,按alt+g才可以有函数跳转功能。2.不安装番茄插件,按F12也可以有跳转功能。3.进公司的VS工程是D:\sync\build\win路径,.sln才是打开工程的方式,一个是VS2005打开的,一个是VS2013打开的。4.公司库里的线程接口,在CmThreadManager.h 里,这个里面是我们的线程库,可以直接拿来用。CreateUserTaskThre..._番茄助手颜色

推荐文章

热门文章

相关标签