How To Kill The Largest Process In An Unresponsive Linux System

When I open a lot of tabs in my browser, my system goes unresponsive for several minutes. I couldn’t move the mouse cursor, or kill a process or close any opened tabs. At that times, I had no choice but to forcibly reset the system. Of course, I use OneTab and The Great Suspender extensions, but they didn’t help much either. I often ran out of memory. While looking for a solution to fix this, I came across Early OOM. For those wondering, it will kill the largest process in an unresponsive system when it has absolutely no other choices. Early OOM checks the amount of available memory and free swap 10 times a second. If both are below 10%, it will kill the largest process.

Why Early OOM? Why not built-in OOM killer?

Before going into further, let me you give a short explanation of OOM killer, also known as Out Of Memory killer. OOM killer is a process that the Kernel uses when the system is critically low on memory. The main task of OOM killer is to continue killing processes until enough memory is freed for the smooth functioning of the rest of the process that the Kernel is attempting to run. OOM killer will choose the best processes that are least important to the system and free up maximum memory and kill them. We can view the oom_score of each process in /proc directory under pid section.

Example:

$ cat /proc/10299/oom_score
1

The higher the value of oom_score of any process, the higher is its likelihood of getting killed by the OOM Killer when the system is running out of memory.

The developer of Early OOM claims that it has one big advantage over the in-kernel OOM killer. As I stated earlier, the Linux oom killer kills the process with the highest score, so the Chrome browser will always be the first victim of the oom killer. To avoid this, Early OOM uses /proc/*/status instead of echo f > /proc/sysrq-trigger. He also claims that triggering the oom killer manually may not work at all in latest Linux Kernel.

Installing Early OOM

Early OOM is available in AUR, so you can install it using any AUR helper programs in Arch Linux and its derivatives.

As you see in the above output, Early OOM will display how much memory and swap you have, what the minimum is, how much memory is available and how much swap is free. Remember it will keep running until you manually stop by pressing CTRL+C.

If both memory and swap reaches below 10%, Early OOM will automatically kill the largest processes until the system has enough memory to run smoothly. You can also configure the minimum percentage value as per your requirement.

Isn’t the point that it kills the largest processes automatically? Usually, when a system freezes, we realize what is happening and we want to kill some programs manually but we can’t. This will do that and then we can, for example, restore browser session afterward if the browser will be killed, despite what it says in the article.

See like a interesting solution for unresponsive system. My only concern is if there is maybe something like time option – if system is more then 5 minutes with very high memory usage then kill that procces. But it’s a nice thing to have definitly!