/proc/sysrq-trigger详解

# 立即重新启动计算机
echo "b" > /proc/sysrq-trigger
 
# 立即关闭计算机
echo "o" > /proc/sysrq-trigger
 
# 导出内存分配的信息 (可以用/var/log/message 查看)
echo "m" > /proc/sysrq-trigger
 
# 导出当前CPU寄存器信息和标志位的信息
echo "p" > /proc/sysrq-trigger
 
# 导出线程状态信息
echo "t" > /proc/sysrq-trigger
 
# 故意让系统崩溃
echo "c" > /proc/sysrq-trigger
 
# 立即重新挂载所有的文件系统 
echo "s" > /proc/sysrq-trigger
 
# 立即重新挂载所有的文件系统为只读
echo "u" > /proc/sysrq-trigger
 
Documentation for sysrq.c
 
Based on kernel version 2.6.38. Page generated on 2011-03-22 22:20 EST.
 
1        Linux Magic System Request Key Hacks
2        Documentation for sysrq.c
3       
4        * What is the magic SysRq key?
5        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6        It is a 'magical' key combo you can hit which the kernel will respond to
7        regardless of whatever else it is doing, unless it is completely locked up.
8       
9        * How do I enable the magic SysRq key?
10      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11      You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when
12      configuring the kernel. When running a kernel with SysRq compiled in,
13      /proc/sys/kernel/sysrq controls the functions allowed to be invoked via
14      the SysRq key. By default the file contains 1 which means that every
15      possible SysRq request is allowed (in older versions SysRq was disabled
16      by default, and you were required to specifically enable it at run-time
17      but this is not the case any more). Here is the list of possible values
18      in /proc/sys/kernel/sysrq:
19         0 - disable sysrq completely
20         1 - enable all functions of sysrq
21       >1 - bitmask of allowed sysrq functions (see below for detailed function
22             description):
23                2 - enable control of console logging level
24                4 - enable control of keyboard (SAK, unraw)
25                8 - enable debugging dumps of processes etc.
26               16 - enable sync command
27               32 - enable remount read-only
28               64 - enable signalling of processes (term, kill, oom-kill)
29              128 - allow reboot/poweroff
30              256 - allow nicing of all RT tasks
31     
32      You can set the value in the file by the following command:
33          echo "number" >/proc/sys/kernel/sysrq
34     
35      Note that the value of /proc/sys/kernel/sysrq influences only the invocation
36      via a keyboard. Invocation of any operation via /proc/sysrq-trigger is always
37      allowed (by a user with admin privileges).
38     
39      * How do I use the magic SysRq key?
40      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41      On x86   - You press the key combo 'ALT-SysRq-<command key>'. Note - Some
42                 keyboards may not have a key labeled 'SysRq'. The 'SysRq' key is
43                 also known as the 'Print Screen' key. Also some keyboards cannot
44                  handle so many keys being pressed at the same time, so you might
45                  have better luck with "press Alt", "press SysRq", "release SysRq",
46                  "press <command key>", release everything.
47     
48      On SPARC - You press 'ALT-STOP-<command key>', I believe.
49     
50      On the serial console (PC style standard serial ports only) -
51                 You send a BREAK, then within 5 seconds a command key. Sending
52                 BREAK twice is interpreted as a normal BREAK.
53     
54      On PowerPC - Press 'ALT - Print Screen (or F13) - <command key>, 
55                   Print Screen (or F13) - <command key> may suffice.
56     
57      On other - If you know of the key combos for other architectures, please
58                 let me know so I can add them to this section.
59     
60      On all - write a character to /proc/sysrq-trigger. e.g.:
61     
62                        echo t > /proc/sysrq-trigger
63     
64      * What are the 'command' keys?
65      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66      'b'     - Will immediately reboot the system without syncing or unmounting
67                your disks.
68     
69      'c'     - Will perform a system crash by a NULL pointer dereference.
 
# 立即重新启动计算机
  echo "b" > /proc/sysrq-trigger
  # 立即关闭计算机
  echo "o" > /proc/sysrq-trigger
  # 导出内存分配的信息 (可以用/var/log/message 查看)
  echo "m" > /proc/sysrq-trigger
  # 导出当前CPU寄存器信息和标志位的信息
  echo "p" > /proc/sysrq-trigger
  # 导出线程状态信息
  echo "t" > /proc/sysrq-trigger
  # 故意让系统崩溃
  echo "c" > /proc/sysrq-trigger
  # 立即重新挂载所有的文件系统
  echo "s" > /proc/sysrq-trigger
  # 立即重新挂载所有的文件系统为只读
  echo "u" > /proc/sysrq-trigger

 
下面将sysrq.txt中的内容附加上一段,全部可以使用的command:

 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66 'b'     - Will immediately reboot the system without syncing or unmounting 67           your disks. 68  69 'c' - Will perform a system crash by a NULL pointer dereference. 70           A crashdump will be taken if configured. 71  72 'd' - Shows all locks that are held. 73  74 'e'     - Send a SIGTERM to all processes, except for init. 75  76 'f' - Will call oom_kill to kill a memory hog process. 77  78 'g' - Used by kgdb on ppc and sh platforms. 79  80 'h'     - Will display help (actually any other key than those listed 81           here will display help. but 'h' is easy to remember :-) 82  83 'i'     - Send a SIGKILL to all processes, except for init. 84  85 'j'     - Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl. 86  87 'k'     - Secure Access Key (SAK) Kills all programs on the current virtual 88           console. NOTE: See important comments below in SAK section. 89  90 'l'     - Shows a stack backtrace for all active CPUs. 91  92 'm'     - Will dump current memory info to your console. 93  94 'n' - Used to make RT tasks nice-able 95  96 'o'     - Will shut your system off (if configured and supported). 97  98 'p'     - Will dump the current registers and flags to your console. 99  100 'q'     - Will dump per CPU lists of all armed hrtimers (but NOT regular 101           timer_list timers) and detailed information about all 102           clockevent devices. 103  104 'r'     - Turns off keyboard raw mode and sets it to XLATE. 105  106 's'     - Will attempt to sync all mounted filesystems. 107  108 't'     - Will dump a list of current tasks and their information to your 109           console. 110  111 'u'     - Will attempt to remount all mounted filesystems read-only. 112  113 'v' - Dumps Voyager SMP processor info to your console. 114  115 'w' - Dumps tasks that are in uninterruptable (blocked) state. 116  117 'x' - Used by xmon interface on ppc/powerpc platforms. 118  119 'z' - Dump the ftrace buffer 120  121 '0'-'9' - Sets the console log level, controlling which kernel messages 122           will be printed to your console. ('0', for example would make 123           it so that only emergency messages like PANICs or OOPSes would 124           make it to your console.) 125 

本文出自 “itnihao的运维技术博客” 博客,请务必保留此出处http://itnihao.blog.51cto.com/1741976/830374


这是一组“ 魔术组合键”,只要 内核没有被完全锁住,不管内核在做什么事情,使用这些组合键能即时打印出内核的信息。
使用sysrq组合键是了解系统目前运行情况的最佳方式。如果系统出现挂起的情况或在诊断一些和内核相关,比较怪异,比较难重现的问题的时候,使用sysrq键是个比较好的方式。
怎么打开和关闭SysRq组合键?
为了安全起见,在红帽企业版Linux里面,默认SysRq组合键是关闭的。 打开这个功能,运行:
# echo 1 > /proc/sys/kernel/sysrq
关闭这个功能:
# echo 0 > /proc/sys/kernel/sysrq
如果想让此功能一直生效,在/etc/sysctl.conf里面设置kernel.sysrq的值为1. 重新启动以后,此功能将会自动
打开。
kernel.sysrq = 1
因为打开sysrq键的功能以后,有终端访问权限的用户将会拥有一些特别的功能。因此,除非是要调试,解决问题,一般情况下,不要打开此功能。如果一定要打开,请确保你的终端访问的安全性。
怎么触发一个sysrq事件?
有几种方式能触发sysrq事件。在带有AT键盘的 一般系统上,在 终端上输入一下组合键:
Alt+PrintScreen+[CommandKey]
例如,要让内核导出内存信息(CommandKey "m"),你应该同时按下Alt 和 Print Screen 键,然后按下 m 键.
提示: 此组合键在Xwindows上是无法使用的。所以,你先要转换到文本 虚拟终端下。如果你当前是在图像界面,
能按Ctrl+Alt+F1转换到 虚拟终端
在串口终端上,要想获得同样的效果,需要先在终端上发送Break信号,然后在5秒内输入sysrq组合键。
如果你在机器上有 root权限,你能把commandkey字符写入到/proc/sysrq-trigger文件。这能帮助你通过 脚本或你不在系统终端上的时候触发sysrq事件。
# echo 'm' > /proc/sysrq-trigger
当我触发一个sysrq事件的时候,结果保存在什么地方?
当一个sysrq命令被触发,内核将会打印信息到内核的环形缓冲并输出到系统控制台。此信息一般也会通过syslog输出到/var/log/messages.
有时候,可能系统已无法响应,syslogd可能无法记录此信息。在这种情况下,建议你设置一个串口终端来收集这个信息。
那些类型的sysrq事件能被触发?
sysrq功能被打开后,有几种sysrq事件能被触发。不同的 内核版本可能会有些不同。但有一些是共用的:
* m - 导出关于 内存分配的信息,
* t - 导出 线程状态信息,
* p - 导出当前CPU寄存器信息和标志位的信息,
* c - 故意让 系统崩溃(在使用netdump或diskdump的时候有用),
* s - 即时同步所有挂载的文件系统,
* u - 即时重新挂载所有的文件系统为只读,
* b - 即时重新启动系统,
* o - 即时关机(如果机器设置并支持此项功能)。

  • 2
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值