The Linux kernel, which powers Ubuntu Server, features an aggressive self-preservation mechanism known as the Out of Memory (OOM) Killer. If your server suddenly runs out of physical RAM and swap space (perhaps due to a massive spike in web traffic or a memory leak in a minor application), the kernel will panic. To prevent the entire operating system from freezing and crashing, the OOM Killer will mathematically calculate which process is using the most memory and instantly terminate it with extreme prejudice.
While this keeps the server online, the OOM Killer often makes disastrous choices. It will frequently identify your primary MySQL database or your core Java application as the biggest memory hog and instantly kill it. Your server stays online, but your actual business application is dead, resulting in a total outage for your users. If you have a mission-critical process that must never be killed under any circumstances—even if it means the entire server crashes—you must completely disable the OOM Killer for that specific process ID.
Disabling the OOM Killer via the /proc Filesystem
You can instruct the kernel to mathematically ignore a specific process by adjusting its oom_score_adj (OOM Score Adjustment) value directly in the virtual /proc filesystem.
- Open a Terminal session (or connect to your server via SSH).
- First, you must identify the exact Process ID (PID) of your critical application. Use the
pidofcommand. For example, to find the PID of the MySQL daemon:pidof mysqld
(Assume the output is4192for this example). - You must now inject a specific value into that process’s configuration file. Run the following command with root privileges, replacing
4192with your actual PID:echo -1000 | sudo tee /proc/4192/oom_score_adj - Verify that the change was successful by reading the file back:
cat /proc/4192/oom_score_adj
(The output should be exactly-1000).
The Technical Impact
The value -1000 is a magic number in the Linux kernel. It completely exempts the process from OOM Killer calculations. If your server runs entirely out of memory, the kernel will viciously slaughter every other application on the system—SSH, Nginx, Python scripts, systemd components—before it even considers touching your protected process.
Warning: This change is temporary and will revert if the process restarts or the server reboots. To make this permanent, you must edit the application’s systemd unit file (e.g., sudo systemctl edit mysql) and add the line OOMScoreAdjust=-1000 under the [Service] block.