3

From Magic SysRq key

The magic SysRq key is a key combination understood by the Linux kernel, which allows the user to perform various low level commands regardless of the system's state. It is often used to recover from freezes, or to reboot a computer without corrupting the filesystem.

What are the low level commands which the keys in the table invoke?

Are they programs that can run in terminal?

How different are the keys from those shortcut keys for gnome or unity?

1
  • 2
    I just removed thanks from two posts you posted today. From your top 10 posts "thanks" in some form or another had to be removed by 7 different people. Please stop including this irrelevant material (read help→tour: no distractions, no chit-chat). so we can focus on answering questions instead of correcting yours. Thank you.
    – Anthon
    May 22, 2015 at 13:13

2 Answers 2

4

In the linux kernel source code in sysrq.c at line 415, there is a struct defined, what should happen when a certain key is pressed. So you see, no command in a terminal is excuted, instead of this, hard coded functions in the kernel are called. So, as long as the kernel is not crashed, you can press those keys, doesn't matter which application is running in the foreground, the kernel handles the keys pressed.

Here is the interessing part:

[...]
415 static struct sysrq_key_op *sysrq_key_table[36] = {
416         &sysrq_loglevel_op,             /* 0 */
417         &sysrq_loglevel_op,             /* 1 */
418         &sysrq_loglevel_op,             /* 2 */
419         &sysrq_loglevel_op,             /* 3 */
420         &sysrq_loglevel_op,             /* 4 */
421         &sysrq_loglevel_op,             /* 5 */
422         &sysrq_loglevel_op,             /* 6 */
423         &sysrq_loglevel_op,             /* 7 */
424         &sysrq_loglevel_op,             /* 8 */
425         &sysrq_loglevel_op,             /* 9 */
426 
427         /*
428          * a: Don't use for system provided sysrqs, it is handled specially on
429          * sparc and will never arrive.
430          */
431         NULL,                           /* a */
432         &sysrq_reboot_op,               /* b */
433         &sysrq_crash_op,                /* c & ibm_emac driver debug */
434         &sysrq_showlocks_op,            /* d */
435         &sysrq_term_op,                 /* e */
436         &sysrq_moom_op,                 /* f */
437         /* g: May be registered for the kernel debugger */
438         NULL,                           /* g */
439         NULL,                           /* h - reserved for help */
440         &sysrq_kill_op,                 /* i */
441 #ifdef CONFIG_BLOCK
442         &sysrq_thaw_op,                 /* j */
443 #else
444         NULL,                           /* j */
445 #endif
446         &sysrq_SAK_op,                  /* k */
447 #ifdef CONFIG_SMP
448         &sysrq_showallcpus_op,          /* l */
449 #else
450         NULL,                           /* l */
451 #endif
452         &sysrq_showmem_op,              /* m */
453         &sysrq_unrt_op,                 /* n */
454         /* o: This will often be registered as 'Off' at init time */
455         NULL,                           /* o */
456         &sysrq_showregs_op,             /* p */
457         &sysrq_show_timers_op,          /* q */
458         &sysrq_unraw_op,                /* r */
459         &sysrq_sync_op,                 /* s */
460         &sysrq_showstate_op,            /* t */
461         &sysrq_mountro_op,              /* u */
462         /* v: May be registered for frame buffer console restore */
463         NULL,                           /* v */
464         &sysrq_showstate_blocked_op,    /* w */
465         /* x: May be registered on ppc/powerpc for xmon */
466         /* x: May be registered on sparc64 for global PMU dump */
467         NULL,                           /* x */
468         /* y: May be registered on sparc64 for global register dump */
469         NULL,                           /* y */
470         &sysrq_ftrace_dump_op,          /* z */
471 };
[...]

Technically you can call them also in a terminal But, you write in a pseudo-file in the proc filesystem called /proc/sysrq-trigger. For example you can do a:

echo b >/proc/sysrq-trigger

... which instantly reboots the machine, without asking or warning or anything. It's the same as when you press SysRq - b.

1
  • For me, /proc/sysrq-trigger is 0200, so you'll need a sudo there.
    – wchargin
    May 22, 2015 at 15:29
2

as linked in the wikipedia article in external links ... you can see that documentation here: Linux Magic System Request Key Hacks

edit:

this is also found in Linux kernel source under the Documentation subdirectory

5
  • thanks. how different are they from those shortcut keys for gnome or unity?
    – Tim
    May 22, 2015 at 11:54
  • the kernel executes these
    – Skaperen
    May 22, 2015 at 11:58
  • Do they invoke programs runnable on terminal?
    – Tim
    May 22, 2015 at 11:58
  • they do not invoke any programs in user space .... they are done intermally in the kernel if the kernel is still running
    – Skaperen
    May 22, 2015 at 12:01
  • the programs they invoke are part of the kernel? Not executable files?
    – Tim
    May 22, 2015 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .