怎样使用sysrq

Linux Magic System Request Key Hacks Documentation for sysrq.c

*  What is the magic SysRq key?

It is a 'magical' key combo you can hit which the kernel will respond to regardless of whatever else it is doing, unless it is completely locked up.

*  How do I enable the magic SysRq key?

You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when configuring the kernel. When running a kernel with SysRq compiled in, /proc/sys/kernel/sysrq controls the functions allowed to be invoked via the SysRq key. By default the file contains 1 which means that every possible SysRq request is allowed (in older versions SysRq was disabled by default, and you were required to specifically enable it at run-time but this is not the case any more).

/proc/sys/kernel/sysrq

Here is the list of possible values in /proc/sys/kernel/sysrq:

0 - disable sysrq completely

1 - enable all functions of sysrq

You can set the value in the file by the following command: echo "number" >/proc/sys/kernel/sysrq

Note that the value of /proc/sys/kernel/sysrq influences only the invocation via a keyboar/proc/sysrq-trigger.d.

/proc/sysrq-trigger.

On all -  write a character to /proc/sysrq-trigger.  e.g.:
        echo t > /proc/sysrq-trigger

*  What are the 'command' keys?

'b'     - Will immediately reboot the system without syncing or unmounting your disks.

'c'    - Will perform a system crash by a NULL pointer dereference. A crashdump will be taken if configured.
'd'    - Shows all locks that are held.
'e'     - Send a SIGTERM to all processes, except for init.
'f'    - Will call oom_kill to kill a memory hog process.
'g'    - Used by kgdb (kernel debugger)
'h'     - Will display help (actually any other key than those listed here will display help. but 'h' is easy to remember :-)
'i'     - Send a SIGKILL to all processes, except for init.
'j'     - Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.
'k'     - Secure Access Key (SAK) Kills all programs on the current virtual console. NOTE: See important comments below in SAK section.
'l'     - Shows a stack backtrace for all active CPUs.
'm'     - Will dump current memory info to your console.
'n'    - Used to make RT tasks nice-able
'o'     - Will shut your system off (if configured and supported).
'p'     - Will dump the current registers and flags to your console.
'q'     - Will dump per CPU lists of all armed hrtimers (but NOT regular timer_list timers) and detailed information about all
          clockevent devices.
'r'     - Turns off keyboard raw mode and sets it to XLATE.
's'     - Will attempt to sync all mounted filesystems.
't'     - Will dump a list of current tasks and their information to your console.
'u'     - Will attempt to remount all mounted filesystems read-only.
'v'    - Forcefully restores framebuffer console 'v'    - Causes ETM buffer dump [ARM-specific]
'w'    - Dumps tasks that are in uninterruptable (blocked) state.
'x'    - Used by xmon interface on ppc/powerpc platforms.
'y'    - Show global CPU Registers [SPARC-64 specific]
'z'    - Dump the ftrace buffer
'0'-'9' - Sets the console log level, controlling which kernel messages will be printed to your console. ('0', for example would make
.

*  I hit SysRq, but nothing seems to happen, what's wrong?

There are some keyboards that produce a different keycode for SysRq than the pre-defined value of 99 (see KEY_SYSRQ in include/linux/input.h), or which don't have a SysRq key at all. In these cases, run 'showkey -s' to find an appropriate scancode sequence, and use 'setkeycodes <sequence> 99' to map this sequence to the usual SysRq code (e.g., 'setkeycodes e05b 99'). It's probably best to put this command in a boot script. Oh, and by the way, you exit 'showkey' by not typing anything for ten seconds.

我们可以不用记住那些讨厌的组合键,而使用sysrq-trigger的方法:通过help命令得到支持的command,再选择使用

All commands

SysRq : HELP :

loglevel(0-9)

reBoot

Crash

terminate-all-tasks(E)

memory-full-oom-kill(F)

kill-all-tasks(I)

thaw-filesystems(J)

saK show-backtrace-all-active-cpus(L)

show-memory-usage(M)

nice-all-RT-tasks(N)

powerOff

show-registers(P)

show-all-timers(Q)

unRaw

Sync

show-task-states(T)

Unmount

show-blocked-tasks(W)


为什么使用 sysrq?

虽然,我们可以从crash dump中得到许多信息,但这需要dump 文件,当然可以手动dump.

最后是在系统运行的时候得到更多信息:

1.串口信息;

2.sysrq;

3.ftrace.

4.?

能通过sysrq得到当前处在可运行状态的进程吗?



你可能感兴趣的:(怎样使用sysrq)