lunes, 4 de mayo de 2009

The Magic "System Request" key in Linux

There's something useful that I keep forgetting when I'm using Linux, something that I would like to keep a record about, and I thought that a good way to do it would be by writing it in this blog.

The System Request key, "SysRq" in English keyboards ("Pet Sis" in Spanish ones, short for "Petición de Sistema") is the useless-looking key that is sitting right next to your (also useless-looking) "Pause" key.

However, this key plays an important role for a Linux System administrator, because it can be used to send system calls directly to the kernel. Sometimes, speaking directly to the kernel is the only way to save the day.

For example... imagine that suddenlty your whole system hangs. It's frozen... there's some process using 100% of the resources of the system.. your mouse doesn't move.. the Control+Alt+F2 key doesnt work... you can't do anything! Arghh!! what to do!!??

In Windows the only possible solution to this situation would be to forcefully disconnect your PC, make it loose any data you had sent and take the risk to damage your hard disk, motherboard, CPU and all the hardware that you were using at that time.

However, if you are using the Linux kernel, there's still some chance for salvation.... sending a System Request...

Press AltGr+SysRq+R (unRaw, releasing your keyboard from X control)
Press AltGr+SysRq+E (tErminate, sending a SIGTERM to close gracefully the running programs)
Press AltGr+SysRq+I (kIll, send a SIGKILL to inmediatelly close the remaining programs)
Press AltGr+SysRq+S (Sync, saving the data to the disk so that you won't loose the last changes)
Press AltGr+SysRq+U (Unmount all the disks, so that they won't be damaged)
Press AltGr+SysRq+B (reBoot the system)

Mnemotecnics


If you are like me, you'll forget this shortcuts easily.
You can do like me, and write in a blog about that... or try to remember it by using some hints. Here are some of them:
"Reboot Even If System Unbelievably Broken"
BUSIER backwards
"Raising Elephants Is So Utterly Boring"
You can also Sync the disks before terminating programs if you want:
"Raising Skinny Elephants Is Utterly Boring" (because if they are fat it would rather be utterly deadly...)


Note: if you are not using a QWERTY keyboard the keys can be different for you
You can also read more about other SysRq shorcuts here: lxr.linux.no/linux/Documentation/sysrq.txt

No hay comentarios: