内核配置选项中要使能CONFIG_MAGIC_SYSRQ选项,这样系统启动之后,会生成/proc/sysrq-trigger节点用于调试。
其次,可以在/etc/sysctl.conf中设置kernel.sysrq=1默认使能sysq功能。也可以通过写/proc/sys/kernel/sysrq节点动态使能sysrq功能。写入不同的值使能不同的功能:
0 - disable sysrq completely |
1 - enable all functions of sysrq |
2 - enable control of console logging level |
4 - enable control of keyboard (SAK, unraw) |
8 - enable debugging dumps of processes etc. |
16 - enable sync command |
32 - enable remount read-only |
64 - enable signalling of processes (term, kill, oom-kill) |
128- allow reboot/poweroff |
256- allow nicing of all RT tasks |
【使用说明】
#echo m > /proc/sysrq-trigger 导出内存分配信息
#echo t > /proc/sysrq-trigger 导出当前任务状态信息
#echo p > /proc/sysrq-trigger 导出当前CPU寄存器和标志位信息
#echo c > /proc/sysrq-trigger 产生空指针panic事件,人为导致系统崩溃
#echo s > /proc/sysrq-trigger 即时同步所有挂载的文件系统
#echo u > /proc/sysrq-trigger 即时重新挂载所有的文件系统为只读
#echo w > /proc/sysrq-trigger转储处于uninterruptable阻塞状态的任务
轻松搞死linux,介绍/proc/sysrq-trigger的强大功能
立即重启计算机 echo "b" > /proc/sysrq-trigger
立即关闭计算机 echo "o" > /proc/sysrq-trigger
导出内存分配的信息 echo "m" > proc/sysrq-trigger (可以用/var/log/message查看)Outputs memory statistics to the console
导出当前CPU寄存器信息和标志位的信息 echo "p" > proc/sysrq-trigger (outputs all flags and registers to the console)
导出线程状态信息 echo "t" > proc/sysrq-trigger (outputs a list of processes to the console)
故意让系统崩溃 echo "c" > proc/sysrq-trigger (crashes the system without first unmounting file systems or syncing disks attached to the system)
立即重新挂载所有的文件系统 echo "s" > proc/sysrq-trigger (attempts to sync disks attached to the system)
立即重新挂载所有的文件系统为只读 echo "u" > proc/sysrq-trigger (attempts to unmount and remount all file systems as read-only)
此外,还有两个类似于强制注销的功能
e ---- kills all processes except init using SIGTERM
i ---- kills all processes except init using SIGKILL