Sobes.tech
Junior — Middle

How does the Linux operating system determine which process to terminate in case of resource shortage or for other reasons?

sobes.tech AI

Answer from AI

In Linux, when resources are scarce, such as RAM, the Out-Of-Memory Killer (OOM Killer) mechanism is triggered. It selects a process to terminate based on several criteria:

  • Process priority (OOM score): processes with lower priority or higher memory consumption are more likely to be killed.
  • Process age: older processes may have a lower priority for termination.
  • Memory used by the process: processes consuming a lot of memory are more often chosen for termination.

The system calculates a special "OOM score" for each process, and the process with the highest value of this score is terminated to free resources. An administrator can influence the behavior of the OOM Killer by changing parameters via /proc or using oom_score_adj.

How does the Linux operating system determine which… - sobes.tech