The CONFIG_MAGIC_SYSRQ option should be enabled in the kernel configuration options, so that after the system starts, the /proc/sysrq-trigger node will be generated for debugging.
Second, you can set kernel.sysrq=1 in /etc/sysctl.conf to enable the sysq function by default. You can also dynamically enable the sysrq function by writing to the /proc/sys/kernel/sysrq node. Writing different values enables different functions:
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 |
【Instructions for use】
#echo m > /proc/sysrq-trigger export memory allocation information
#echo t > /proc/sysrq-trigger Export current task status information
#echo p > /proc/sysrq-trigger Export current CPU register and flag information
#echo c > /proc/sysrq-trigger generates a null pointer panic event, which artificially causes the system to crash
#echo s > /proc/sysrq-trigger syncs all mounted filesystems instantly
#echo u > /proc/sysrq-trigger instantly remounts all filesystems as read-only
#echo w > /proc/sysrq-trigger Dump tasks in uninterruptable blocking state
Easily kill linux, introduce the powerful functions of /proc/sysrq-trigger
Reboot the computer now echo "b" > /proc/sysrq-trigger
Shut down the computer immediately echo "o" > /proc/sysrq-trigger
Export memory allocation information echo "m" > proc/sysrq-trigger (can be viewed with /var/log/message) Outputs memory statistics to the console
Export current CPU register information and flag bit information echo "p" > proc/sysrq-trigger (outputs all flags and registers to the console)
Export thread status information 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)
Remount all filesystems immediately echo "s" > proc/sysrq-trigger (attempts to sync disks attached to the system)
Immediately remount all file systems as read-only echo "u" > proc/sysrq-trigger (attempts to unmount and remount all file systems as read-only)
In addition, there are two functions similar to force logout
e ---- kills all processes except init using SIGTERM
i ---- kills all processes except init using SIGKILL