Magic Key in Linux

You’re working on a serious project or writing an important assignment(on linux obviously :p)  and suddenly your system freezes.God Bless You!.The instantaneous panic will unconsciously make you Ctrl+Alt+Del if you’ve shifted from Windows and are still getting accustomed to linux habits.Even a regular linux user may face problems if he is not aware of the ‘magic’ he possesses.

The ‘magic‘ is forever-ignored SysRq key on our keyboard.It  can send commands directly to the Linux kernel. You can use it to recover from freezes or cleanly restart your system, even if nothing appears to be responding.The magic SysRq key is implemented as part of Linux’s keyboard driver – it will work as long as the Linux kernel is still running.

Using SysRq key

This key is generally the same as Print Screen key and the magic combination of using it is Alt+SysRq To use this key combination,your Linux kernel must have been compiled with the CONFIG_MAGIC_SYSRQ compile option – most Linux distributions will have this enabled by default. Assuming it’s compiled into your kernel, it can be enabled or disabled on a running system by changing the value of /proc/sys/kernel/sysrq. To check if it’s enabled, run the following command:

cat /proc/sys/kernel/sysrq

If a non-zero number is returned it is enabled otherwise not.We may enable it with:

echo “1” > /proc/sys/kernel/sysrq

Recovering from frozen X Server:

If your X server (the program that runs your graphical desktop) freezes, you may find yourself unable to use your system. There are a few magic SysRq commands that can help:

  • Alt + SysRq + r – Takes the keyboard out of raw mode, taking control away from the X server. After running this combination, you should be able to use the Ctrl + Alt + F1 (and other F-key) keyboard shortcuts to switch to another console and restart X.
  • Alt + SysRq + k – Kills all programs on the current virtual console, including X.

Restarting the system:

We can cleanly end processes, flush data to disk, unmount all file systems, and restart your computer. To perform this process, press and hold the Alt + SysRq key combination and – while holding the Alt and SysRq keys down — type the following keys in order, pausing for some seconds in between each key:


Remeber it with “Raising Elephants Is So Utterly Boring” :p.Functions of keys are:

  • r – Puts the keyboard into raw mode, taking control of it away from the X server.
  • e – Sends the terminate signal to all processes, asking them to end gracefully.
  • i – Sends the kill signal to all processes, forcing them to end immediately.
  • s – Flushes data from your cache to disk.
  • u – Remounts all file systems read-only.
  • b – Reboots your computer.

More Commands: Here are some other actions you can perform with the magic SysRq key. To perform an action, press and hold the Alt + SysRq keys while typing the letter:

  • n – Resets the nice level (priority) of all high and realtime priority processes.
  • f – Calls oom_kill, which will kill a memory-hogging process.
  • o – Shuts off the computer.

This information is enough for an average linux user.For complete documentation, Go here.


5 thoughts on “Magic Key in Linux”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s