「LINUX-KERNEL」- SysRq

认识

如果正在从事内核开发、设备驱动程序或运行可能导致 Kernel 崩溃的代码,系统将被冻结(卡死),SysRq 能够帮助我们逃离卡死的局面,其为是 Linux Kernel 中的组合快捷键。

组成

WIP

性质

它允许用户执行各种低级命令(不管系统状态如何)。

组合键由 Alt+SysRq+commandkey 组成。在许多系统中,SysRq 键是 Print Screen 键。

ThinkPad T540p Alt + PrtSc

首先,启用:echo “1” > /proc/sys/kernel/sysrq
然后,执行:echo “b” > /proc/sysrq-trigger(实现重启)

常用命令

‘k’ – Kills all the process running on the current virtual console.
‘s’ – This will attempt to sync all the mounted file system.
‘b’ – Immediately reboot the system, without unmounting partitions or syncing.
‘e’ – Sends SIGTERM to all process except init.
‘m’ – Output current memory information to the console.
‘i’ – Send the SIGKILL signal to all processes except init
‘r’ – Switch the keyboard from raw mode (the mode used by programs such as X11), to XLATE mode.
‘s’ – sync all mounted file system.
‘t’ – Output a list of current tasks and their information to the console.
‘u’ – Remount all mounted filesystems in readonly mode.
‘o’ – Shutdown the system immediately.
‘p’ – Print the current registers and flags to the console.
‘0-9’ – Sets the console log level, controlling which kernel messages will be printed to your console.
‘f’ – Will call oom_kill to kill process which takes more memory.
‘h’ – Used to display the help. But any other keys than the above listed will print help.

应用

它通常用于从冻结中恢复(或在不损坏文件系统的情况下)重新启动计算机。

Kernel Panic

存储故障导致文件系统只读,进而无法执行重启命令。

安全重启

r ⇒ unRaw (take control of keyboard back from X11,
e ⇒ tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
i ⇒ kIll (send SIGILL to all processes, forcing them to terminate immediately),
s ⇒ Sync (flush data to disk),
u ⇒ Unmount (remount all filesystems read-only),
b ⇒ reBoot.

参考

Wikipedia/SysRq
How to enable all SysRq functions on Linux