Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We've all experienced it--some program is asked to do something that requires a huge amount of memory. It dutifully tries to allocate all this memory, and the system immediately begins thrashing, swapping endlessly and becoming sluggish or non-responsive.

I most recently experienced this on my Ubuntu laptop due to a Matlab script trying to allocate a ridiculously huge matrix. After ~5+ minutes of thrashing, I was able to Ctrl-F1 to a console and kill Matlab. I would much rather have some hot-key that would have given me control of the system immediately and allowed me to kill the offending process; or, perhaps, simply silently refuse to allocate such a large buffer.

  1. What is the quickest way to regain control of a Linux system that has become nonresponsive or extremely sluggish due to excessive swapping?

  2. Is there an effective way to prevent such swapping from occurring in the first place, for instance by limiting the amount of memory a process is allowed to try to allocate?

share|improve this question
up vote 10 down vote accepted

Press Alt-SysRq-F to kill the process using the most memory:

  • The SysRq key is usually mapped to the Print key.
  • If you're using a graphical desktop you might need to press Ctrl-Alt-SysRq-F in case pressing Alt-SysRq triggers another action (e.g. snapshot program).
  • If you're using a laptop you might need to press a function key too.
  • For more information read the wikipedia article.
share|improve this answer

You may be able to press Ctrl-z to suspend the program. Then you can do kill %1 (or whatever the job number is or you can use the PID).

You can use the ulimit command to try to limit the amount of memory available to a process.

share|improve this answer
Ctrl-Z is nice, but usually I am running a Matlab GUI and have lost track of the controlling terminal, so have no easy way to issue the Ctrl-Z keypress. It would be nice if the GUI had a hot key to send SIGSTOP to whatever application has focus! – nibot Feb 22 '11 at 1:21
You can run kill -STOP <pid> which will do the same thing as Ctrl-Z. – hlovdal Feb 24 '11 at 0:30
Yes, but the whole problem is that, in such a situation, the system is so non-responsive that it takes a long time (or forever) to get to a command prompt. – nibot Feb 24 '11 at 1:19

I've made a prototype script for this purpose -

It's so far just a prototype, but running for one day in production it has already saved two servers from needing a hard reboot.

This script does not kill processes, but suspends them temporary.

Of course, "buy more memory" or "don't use swap" are two alternative, more traditional answers on the question "how to avoid thrashing?"

share|improve this answer

It would be nice if the GUI had a hot key to send SIGSTOP to whatever application has focus!

There is always the classical xkill command (from xorg-x11-apps-7.4-14.fc14.src.rpm on my system). I guess it should not be too difficult to make a clone that sends SIGSTOP instead of killing the target window.

share|improve this answer
How can i make xkill start up quickly at the press of some key combination? – nibot Feb 24 '11 at 1:20
I am not sure. I assume both gnome and KDE have some global shortcut functionality that can be used to launch programs. – hlovdal Feb 24 '11 at 2:09

You can use CGroups to limit resource usage and prevent such problems:

share|improve this answer
Please include the essential information in your answer and use the link just for attribution and further reading. That link describes what CGroups is, but it is not obvious from the link how to actually use it to solve the problem. Can you expand your answer to describe the solution to the question? Thanks. – fixer1234 Jun 8 '15 at 5:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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