1. # echo 1 >/proc/sys/kernel/sysrq
2. # echo B >/proc/sysrq-trigger
1./proc/sys/kernel/sysrq
1 is written to the SysRq file in order to turn on the SysRq feature. According to Linux/documentations/sysrq.txt, SYSRQ represents the Magic System Request Key. When this feature is turned on, it will respond to any action you require as long as the kernel is not dead. However, this requires kernel support (CONFIG_MAGIC_SYSRQ option). Write to/PROC/SYS/KERNEL/SYSRQ 0 is off SysRq function, write 1 is on, other options refer to Sysrq.txt. It is important to note that the value in/PROC/SYS/KERNEL/SYSRQ only affects the operation of the keyboard.
So how do you use the SYSRQ key?
On the x86 platform, the combination keys "<ALT> + SYSRQ + <command key>" make up the SYSRQ key to perform various functions. However, there may not be a SysRq key on some keyboards. The SYSRQ key is actually the "Print screen" key. And maybe some keyboards do not support pressing three keys at the same time, so you can hold down the "Alt key", click "SysRq Key", and then click "<command key>", if you are lucky, this will have effect. But rest assured, the keyboard now generally supports simultaneous press 3 or more than 3 keys.
<command key> There are many, here only a few to say, others can refer to the Sysrq.txt file.
· ' B '-will restart the system immediately, and will not control whether you have data not written back to disk, do not unmount the disk, but completely shut down immediately
· ' O '--will turn off the machine
· ' s '--will sync all the file systems that are hanging on
· ' U '-will re-hang all file systems as read-only properties
2./proc/sysrq-trigger
It can be seen from the name of the file that the two are related. The characters written in/proc/sysrq-trigger are actually the characters that correspond to the keys in the Sysrq.txt, and their functions are the same as above.
Therefore, these two lines of command first turn on the SYSRQ function, and then use the ' B ' command to restart the computer immediately.
/proc/sysrq-trigger what can be done with this file?
# Restart your computer now (reboots the kernel without first unmounting file systems or syncing disks attached to the system)
echo "B" >/proc/sysrq-trigger
# Turn off the computer immediately (shuts off the system)
echo "O" >/proc/sysrq-trigger
# Export memory allocation information (can be viewed with/var/log/message) (Outputs memories Statistics to the console)
echo "M" >/proc/sysrq-trigger
# Export Current CPU register information and flag bit information (Outputs all flags and registers to the console)
echo "P" >/proc/sysrq-trigger
# Export Thread state information (Outputs a list of processes to the console)
echo "T" >/proc/sysrq-trigger
# deliberately let the system crash (crashes the systems without first unmounting file systems or syncing disks attached to the system)
echo "C" >/proc/sysrq-trigger
# immediately re-mount all file systems (attempts to sync disks attached to the system)
echo "S" >/proc/sysrq-trigger
# immediately re-mount all the file systems as read-only (attempts to unmount and remount all files system as Read-only)
echo "U" >/proc/sysrq-trigger
There are also two features, similar to the Force logoff feature
E-kills all processes except init using SIGTERM
I-kills all processes except init using SIGKILL
Linux Remote forced restart/proc/sys/kernel/sysrq/proc/sysrq-trigger