Original article: http://blog.chinaunix.net/uid-317451-id-92580.html
Linux memory management has a set of mechanisms: when the system memory overflows, it will select one or several appropriate processes to kill to maintain the stable operation of the system. However, a machine is a machine after all. Although it tries its best to select the processes that are actually the culprit, it will inevitably make mistakes or be unfair. In the end, the system will become incomplete due to mistaken killing, it cannot even run normally. At this time, it may be necessary to manually intervene and guide the system to make the right choice.
This behavior is controlled by adjusting/proc/[pid]/oom_adj in the corresponding directory of the process. The value range of oom_adj is-17 ~ 15. When the oom_adj of a process is-17, the system will not kill it, -Between 16 and 15, the/proc/[pid]/oom_score value of the process increases exponentially (K * 2 ^ N). That is to say, the probability of their being killed increases exponentially. In addition, the first process (process no. 1) Init is not in the kill list, regardless of its oom_adj value. In the past, only the process with system resource management permissions (cap_sys_resource) can adjust the oom_adj value. If the process is killed, no special permissions are required, we should not deprive it of suicide or the right of its owner to put it on a cliff.
The specific actions to prevent a process from being killed are as follows:
Root @ gentux xiaosuo # pgrep restart-daemon 4595 6664 Root @ gentux xiaosuo # Cat/proc/4595/oom_score 559 Root @ gentux xiaosuo # echo-17>/proc/4595/oom_adj Root @ gentux xiaosuo # Cat/proc/4595/oom_score 0 |
Note: this technique is dangerous. unless you are sure that the process you prohibit is okay, do not try to make stupid settings. Otherwise, you will be at your own risk.
References:
[1] OOM killer
[2]
Understanding/proc