Practical skills to prevent system processes from being accidentally killed

Source: Internet
Author: User

Linux memory management has a set of mechanisms: when the system memory overflows, it will choose 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 is difficult to determine which processes to choose to kill at this time, and sometimes errors will inevitably occur, or unfair. In the end, the system still becomes incomplete due to false positives, and even fails to 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 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 in the form of K * 2 ^ n, that is, the probability of killing them increases exponentially. In addition, the first process in the beginning of the day is 1) init is not included in the list, regardless of its oom_adj value. It turns out that only the process with the system resource management permission 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 dbus-daemon45956664root@gentux xiaosuo # cat /proc/4595/oom_score559root@gentux xiaosuo # echo -17 > /proc/4595/oom_adjroot@gentux xiaosuo # cat /proc/4595/oom_score0
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.

Related Articles]

  • Monitors and protects process security in Linux
  • Linux-based cluster system key technology analysis process placement and migration in quarter 5th
  • From cainiao to master: comprehensive understanding of System Processes

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.