QA
Intermediate LevelLinux Commands & SysAdmin

How does the Linux OOM Killer select processes to terminate when RAM is exhausted?

❓ Interview Prompt: Explain Out-Of-Memory (OOM) Killer, memory exhaustion, oom_score calculation, oom_score_adj adjustment, and dmesg debugging.

When physical RAM and swap space are completely exhausted, the Linux kernel invokes the OOM Killer (Out-Of-Memory Killer) to avoid a full kernel panic:

Selection Algorithm ('oom_score'):

Calculates an 'oom_score' (0-1000) for every process based on RAM consumption percentage. The process with the highest score is terminated!

Adjusting Score ('oom_score_adj'):

Protect critical processes (e.g. database daemons) by setting 'echo -1000 > /proc/<PID>/oom_score_adj' to prevent OOM termination.

Code Implementation Example

bash
# Protect MySQL daemon (PID 1234) from being terminated by OOM Killer
echo -1000 | sudo tee /proc/1234/oom_score_adj

# Check system log for past OOM Killer termination events
sudo dmesg -T | grep -i oom
💡Protecting critical processes from OOM Killer and checking kernel crash logs.
🎯 Interview Key Takeaway

Set oom_score_adj=-1000 on critical database processes to prevent the OOM Killer from terminating them during memory pressure.

#OOM Killer#oom_score#Memory Exhaustion#Intermediate
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?