Pinterest Stumbleupon Whatsapp
Ads by Google

Linux systems are known for their stable operation, designed to be operational without reboot for years. However if you still manage to pull a string and freeze up your computer there are quite a few ways to get the system back to work. You can login to a virtual console, use pgrep and pkill, use xkill, system monitor and kill the offending process if you are sure about them. Or if nothing works you can hit the power button may be? But before you head towards that power button there is one last magical way to get back your system, and I am going to talk about it in this article.

First off I am sure there would be many of us who don’t know that their keyboard has a sysrq key. Is it? Or perhaps you had forgotten about it? Yes its that PrintScreen/SysRq key that we are going to MakeUseOf in this article.

What is a Magic SysRq Key

A Magic SysRq Key lets you send some low level commands independent of the system state. This means that if the system is frozen you can use these key combinations to perform certain actions and thus regain control.

So what’s the magic? Well if you are ever stuck with an unresponsive system try

Alt+PrintScreen+r+s+e+i+u+b.

Ads by Google

Pheew! So how many hands do you need to do this? Or should you use your toes? Well, actually you only press and hold Alt and PrintScreen together, the other keys are pressed one at a time and then released. There is quite a lot happening when you do this. ‘r’ ‘s’ ‘e’ ‘i’ ‘u’ ‘b’ actually stand for seperate commands:

  • r – takes the control of the keyboard back from X.
  • s – writes the data from the disc cache to the hard disk.
  • e – sends SIGTERM to all processes except init.
  • i – sends SIGKILL to all processes except init
  • u – remounts all the filesystems readonly (basically a measure to help you reboot safely)
  • b – reboots the system

As you see that pressing each letter accomplishes certain tasks, so it makes sense to press them one by one while having the Alt+PrintScreen combination depressed. Give sufficient time before pressing the next key to allow the system to perform all the tasks as requested by the Magic SysRq Key combination

Other Magic Commands

That’s not all. Alt+PrintScreen+r+s+e+i+u+b is just one special combination of the commands that helps you recover an unresponsive system. There are other commands available as well:

0 – 9 sets the console log level, controlling which kernel messages will be printed to your console so that you don’t get flooded.
b restarts the system without making steps to ensure that the conditions are good for a safe reboot, using this key alone is like doing a cold reboot.
e sends SIGTERM to all processes except init.
f call Out Of Memory Killer, which will kill a process that is consuming all available memory.
h displays help about the SysRq keys on a terminal though in actuality you can use any key except for the ones specified, to display help.
i sends SIGKILL to all processes except init.
k kills all processes on the current terminal.
l sends SIGKILL to all processes, including init.
m dumps memory info to your console.
o shuts down the system via ACPI or in older systems, APM.
p dumps the current registers and flags to your console.
q dumps all timers info to your console.
r takes keyboard and mouse control from the X server.
s writes all data from the disc cache to the hard-discs, it is a sync and is necessary to reduce the chances of data corruption.
t dumps a list of current tasks and info to your console.
u remounts all mounted filesystems read-only. After using this key, you can reboot the system with Alt+SysRq+B without harming the system.
w dumps uninterruptable (blocked) state tasks.

Alt+Printscreen is also the keyboard shortcut for screenshot of the active window under Gnome and some other window managers.Make sure you have Magic SysRq Keys enabled on your system. Magic SysRq keys/commands work only if the kernel was compiled with the CONFIG_MAGIC_SYSREQ option.

You can also use proc sysrq trigger calls to control the behavior of sysrq keys. Generally you only need to know that

echo 0 > /proc/sys/kernel/sysrq disables sysrq keys

and

echo 1 > /proc/sys/kernel/sysrq enables sysrq keys

There are other numbers with special meanings like 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 signaling of processes (term, kill, oom-kill), 128 – allow reboot/poweroff, 256 – allow nicing of all RT tasks(control the nice level(priority) of Real Time tasks)

Alternatively adding kernel.sysrq=1 in /etc/sysctl.conf file will also enable sysrq keys.

Please be extra careful while editing configuration files.

There you have it. Your very own contingency plan. If you find the combination difficult to memorize you may write it down and paste it on monitor, or just remember “Raising Skinny Elephants Is Utterly Boring”.

Magic SysRq keys are nothing new, they have been a feature of the kernel since quite some time now. Have you ever got the chance to use them? or do you prefer some other way? Share with us in the comments.

  1. Fliliaatole
    October 10, 2009 at 7:30 pm

    I found this funny video site with 2 original video's up here are the teaser

    " How to ruin somebodies wedding in 10 easy steeps"

    " 10 Things you don't want to do on your first date"

    Check it out link is in my signature.

  2. Noble
    March 31, 2009 at 10:11 pm

    Heey! The babes are here! This is my best site to visit. I make sure I am alone in case I get too hot. Post your favorite link here.

    • vaivaswatha
      July 30, 2009 at 4:11 am

      Great... I had a problem with my video drivers and X used to crash. I had to login via ssh and reboot the system. This is a really useful alternate (and more convenient too). :)

  3. serbianlad
    January 26, 2009 at 4:45 pm

    Wow, that's some control at your fingerprints. Too bad I'm at work and there is nothing but windoz around. I'll try it at home :)

  4. Chiron613
    December 20, 2008 at 4:07 pm

    I'm not sure how much difference it makes, but the sequence I learned was r-e-i-s-u-b. The way I remember it is simply to recognize that it spells 'busier' backwards - and I'm trying to make my computer less 'busy'.

  5. Captain_Tux
    November 12, 2008 at 9:04 am

    Hello!

    Great article! I'm learning a lot, but I'm still a Linux newbie, soooooooooooooooooo... Where do I add "kernel.sysrq=1 in /etc/sysctl.conf" in case I need to use this key combo?

    Thanks!

  6. alvare
    November 11, 2008 at 11:04 am

    I used to bother my non-unix friend by pressing Alt+SysRq+o while they were using my DebianBox and bullshiting Linux :)

  7. BasketCase
    November 10, 2008 at 9:52 pm

    This also works for servers with serial consoles. If you send an enter then a break and then one of the SysRq keys it will have the same effect with the output going to the serial port.

  8. Jeenu
    November 10, 2008 at 2:57 am

    Quite interesting and useful. Although I've noticed this SysRq thing written on the keyboard, I hardly ever bothered to think about it. Thanks for a great article.

  9. techniqueal t.
    November 9, 2008 at 9:37 am

    fantastic tip! very useful info. keep it up! ^_^

  10. Varun Kashyap
    November 9, 2008 at 8:36 am

    Yeah, forgot to mention the other one. Some say reisub is better and others say rseuib is better.

    Both even have elephant mnemonics!! ;)

    I used rseuib the one time I have had to use it till date and went pretty well. Next time I will try reisub and let you know how it went. May have to wait for a really long time coz we all know about the Linux stability

  11. gabe565
    November 9, 2008 at 8:22 am

    I'm loving that you guys are starting to talk about Linux, keep the great articles coming!

    I've never had a time when I would have needed this, Linux is just too stable!

  12. kim
    November 9, 2008 at 7:13 am

    Since SIGTERM might cause processes to write something to disk(which might then get stuck in the write cache) you should use this ordering: reisub

    It also has the advantage of being easier to remember, since it is the word "busier" backwards.

  13. Mackenzie Morgan
    November 8, 2008 at 10:59 pm

    This will only work if the issue is just that some process is using a lot of resources. If it's a kernel panic, you're still screwed. Hold down the power button in that case. In all honesty, though I've known about Magic SysRq for a long while, I've never had any use for it. The only time a Linux system locks up, in my experience, is when there's a kernel panic. And there's nothing that can be done about a kernel panic. The kernel will not respond to Magic SysRq once it panics.

    And I was taught it as REISUB, not RSEIUB.

  14. Scott
    November 8, 2008 at 10:26 pm

    Awesome article. I've seen the first sequence you mentioned in the article mentioned before, but not the other command options. Very useful information.

  15. magnet14
    November 8, 2008 at 4:54 pm

    This is about Linux. Now what about windows? :P

    • Varun Kashyap
      November 9, 2008 at 3:04 am

      The power off button ;)

    • Alan
      November 9, 2008 at 12:50 pm

      Regain control of your system if you're using Windows? Install Linux.

    • 13thSlayer
      January 13, 2010 at 8:09 am

      Possible actually, first run "reg add HKLM\SYSTEM\CurrentControlSet\Services\i8042prt\Parameters /v CrashOnCtrlScroll /t REG_DWORD /d 1" on Command Line and reboot your machine. Thereafter, hold Ctrl and hit Scroll Lock twice to force a soft reboot.

  16. matt
    November 8, 2008 at 3:28 pm

    will this work if no one is logged in?

    • Mackenzie Morgan
      November 8, 2008 at 11:00 pm

      Yes, of course. Magic SysRq talks directly to the kernel.

  17. alfredwesterveld
    November 8, 2008 at 2:26 pm

    Good stuff, I like it that makeuseof.com is discussing more complicated stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *