I'm experiencing system hangs which seem to correlate with high RAM usage levels (though swap is mostly unused).

I'd like to be able to kill thunderbird and other memory hogs via a script with a magic sysreq combo.

Is there any way of running a script via Alt + SysReq?

  • 1
    You might be interested by the perf tools to help you investigate what is happening. – meuh Mar 3 '18 at 16:45

You can hook a script into Alt+SysRq if you modify the kernel sources. The Alt+SysRq handling is defined in drivers/tty/sysrq.c. For instance, Alt+SysRq+f calls the sysrq_handle_moom() function that schedules a call of out_of_memory() to kill a process.

static void moom_callback(struct work_struct *ignored)
    /* ... */
    if (!out_of_memory(&oc))
    /* ... */

static DECLARE_WORK(moom_work, moom_callback);

static void sysrq_handle_moom(int key)
static struct sysrq_key_op sysrq_moom_op = {
        .handler        = sysrq_handle_moom,
        .help_msg       = "memory-full-oom-kill(f)",
        .action_msg     = "Manual OOM execution",
        .enable_mask    = SYSRQ_ENABLE_SIGNAL,
  • 2
    I have no idea how that works, but I would guess that forking (which is probably neccessary to spawn a script) is not guaranteed to succeed under the kind of circumstances where Alt+SysRq is typically used, so changing the kernel for this might be a lot of work for nothing. – Henrik Mar 3 '18 at 9:07
  • I get a load average of approx 100, but things still w...o...r...k....... – Tom Hale Mar 5 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.