Ways to prevent Linux system processes from being killed

Source: Internet
Author: User

Linux memory management has a set of mechanisms: when the system memory overflow, it will select a/several appropriate processes to kill to maintain the stable operation of the system. But the machine is a machine, although it makes every effort to choose those who are really the culprit of the process, but inevitably will be wrong, or unfair, in the end the system or because of manslaughter and become incomplete, or even the operation of the game. This time may be needed: artificial intervention, guidance system to make the right choice.

The control of this behavior is achieved by adjusting the/proc/[pid]/oom_adj in the corresponding directory of the process, where Oom_adj's value return is -17~15, and when the Oom_adj of the process is-17, the system will not kill it,-16 to 15 makes the process/proc/[ Pid]/oom_score values are incremented in the form of exponential (K * 2 ^ n), which means that their likelihood of being killed is exponentially increased. In addition, the first epoch-making process (process number 1) Init is not killed either, regardless of its oom_adj value. Originally only the process of system resource management permission (Cap_sys_resource) can make the adjustment of the Oom_adj value, now if it is to the process of the possibility of being killed does not need any special authority, we also really should not deprive it of suicide or its owner intentionally put it onto the cliff right.

The specific actions that prohibit a process from being killed are:

root@gentux xiaosuo # pgrep dbus-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 can be 100% sure that you forbid the process of being killed is not a problem, or do not try to do stupid settings, otherwise the consequences of the ego.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.