The OOM Killer at Work
If you are pushing your Ubuntu machine to its limits—perhaps rendering a complex 3D model, compiling a massive codebase, or simply running a web browser with hundreds of tabs open on a machine with limited RAM—you might experience a jarring event. Suddenly, without warning or a crash dialogue, the active window you were working in simply vanishes. It hasn’t minimized; the application has been completely closed. This is the Linux Out-Of-Memory (OOM) Killer in action. When the system detects that it is dangerously low on RAM and swapping space, the OOM Killer automatically selects a process (often the one consuming the most memory) and forcibly terminates it to prevent the entire operating system from freezing and crashing.
Adjusting OOM Score Adjustments (OOMScoreAdjust)
You cannot completely disable the OOM Killer without risking systemic instability, but you can stop Ubuntu from automatically closing a specific, critical window by protecting its process from the killer’s crosshairs.
You must adjust the ‘oom_score_adj’ value for the specific application you want to protect. This requires the terminal. First, find the Process ID (PID) of the application you want to protect. Open a terminal (Ctrl+Alt+T) and type pidof [application_name] (e.g., pidof firefox). Note the number returned. Next, you must adjust its score. A lower score makes it less likely to be killed. Type the following command, replacing [PID] with the number you found: sudo echo -1000 > /proc/[PID]/oom_score_adj. You will need to enter your administrator password. A score of -1000 effectively renders the process immune to the OOM Killer. Note that this change only lasts until the application is closed or the computer is restarted; for a permanent solution, you would need to write a custom systemd service wrapper for that application.