Magic SysRq key

无意中发现这篇《linux 死机了怎么办》,感觉挺好玩的。google了下,在wikipedia找到详细的介绍。凭借我3.5级的E文水平,整理出来和大家分享。

 

Magic SysRq key 是linux内核提供的一组按键序列。他们对应一些系统的底层操作,能够在software debug和系统应急方面发挥作用。

要用上这个Magic key,有三个基本条件:

  1. 键盘上有SysRq键;(呵呵...)
  2. 所使用的内核,在编译时打开了CONFIG_MAGIC_SYSRQ选项;
    # 验证方法
    grep -F CONFIG_MAGIC_SYSRQ /boot/config-`uname – r`
    # y表示已开启
    CONFIG_MAGIC_SYSRQ=y
  3. 系统配置Magic key为可用。
    #查看/etc/sysctl.conf,确认
    kernel.sysrq = 1
    #如果先前为0,更改配置后使用以下代码激活
    sysctl -p

使用方法:按住Alt和SysRq键,再逐次按下相应功能键(详见下表)。

公式:Alt + SysRq + 相应功能键(或者按键序列)

按下之前要看清键盘布局,不同的布局按键序列不同。而且按按键序列时,每个功能键之间应该间隔一定时间。

话说通常的键盘SysRq键和截屏键(Print Screen)合在一起。

Action QWERTY Dvorak AZERTY
Set the console log level, which controls the types of kernel messages that are output to the console 0 through 9 0 through 9 0 through 9
(without using shift)
Immediately reboot the system, without unmounting partitions or syncing b x b
Reboot kexec and output a crashdump c j c
Display all currently held Locks d e d
Send the SIGTERM signal to all processes except init (PID 1) e . e
Call oom_kill, which kills a process to alleviate an OOM condition f u f
When using Kernel Mode Setting, provides emergency support for switching back to the kernel's framebuffer console[3] g i g
Output a terse help document to the console
Any key which is not bound to a command should also do the trick
h d h
Send the SIGKILL signal to all processes except init i c i
Kill all processes on the current virtual console (Can be used to kill X and svgalib programs, see below)
This was originally designed to imitate a Secure Access Key
k t k
Show a stack backtrace of all currently executing tasks l n l
Output current memory information to the console m m ,
Reset the nice level of all high-priority and real-time tasks n b n
Shut off the system o r o
Output the current registers and flags to the console p l p
Display all active high-resolution timers and clock sources. q ' a
Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE mode r p r
Sync all mounted filesystems s o s
Output a list of current tasks and their information to the console t y t
Remount all mounted filesystems in read-only mode u g u
Output Voyager SMP processor information v k v
Display list of blocked (D state) tasks w , z

针对系统僵死,需要重启的情况,前人总结了两套功能键按键序列。

一、

unRaw      将键盘控制从 X Server 那里抢回来
 tErminate 给所有进程发送 SIGTERM 信号,让他们自己解决善后
 kIll      给所有进程发送 SIGKILL 信号,强制他们马上关闭
  Sync     将所有数据同步至磁盘
  Unmount  将所有分区挂载为只读模式
reBoot     重启

* 记为buisier的反序(busy的比较级),时间控制:R – 1 秒 – E – 30 秒 – I – 10 秒 – S – 5 秒 – U – 5 秒 – B

* 摘自blog.upsuper.org.cn/what-to-do-if-linux-crash/

二、

"Raising Skinny Elephants Is Utterly Boring"

两套序列功能一致,都是尽量让系统的关机正常化。不同在于选择Sync的时机。

 

 

话说评论对Magic key用在系统应急上很是不屑,因为很多发行版默认都不开启这项功能。原因是避免快捷键冲突和安全方面的考虑。看来这个又是“砖家"的“砖利”!

感兴趣的同学可以看看这里www.ibm.com/developerworks/cn/linux/l-cn-sysrq/index.html

新鲜注册,打个记号

为了避免一贯的完美“洁癖”,这里将会一片狼藉!

 


以下就是注册时见到的一切

 

 	$$\begin{vmatrix}1 & 2\\3 &4\end{vmatrix}$$ $$\begin{Vmatrix}1 & 2\\3 &4\end{Vmatrix}$$

unRaw      将键盘控制从 X Server 那里抢回来
 tErminate 给所有进程发送 SIGTERM 信号,让他们自己解决善后
 kIll      给所有进程发送 SIGKILL 信号,强制他们马上关闭
  Sync     将所有数据同步至磁盘
  Unmount  将所有分区挂载为只读模式
reBoot     重启

word "BUSIER" backwards, is often useful.[5] It stands for

unRaw      (take control of keyboard back from X),  
 tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
 kIll      (send SIGKILL to all processes, forcing them to terminate immediately), 
  Sync     (flush data to disk),
  Unmount  (remount all filesystems read-only),
reBoot.

TinEye

TinEye is a reverse image search engine. more...

 

欢迎路过的口水和鸡蛋,谢谢!