Linux limits the CPU and memory usage of user processes
Source: Internet
Author: User
Linux restricts the CPU and memory usage of user processes-Linux general technology-Linux programming and kernel information. The following is a detailed description. By Kang
A few days ago, I posted an article on Netease blog titled "limits the CPU usage of user processes in linux". When talking about limiting the CPU usage of processes, I gave a shell script code as follows:
Ps is used to obtain process information. In fact, the % CPU column in ps indicates the ratio of the actual CPU time occupied by the process to its survival time. This value reflects the CPU consumption of the process, however, the percentage of CPU time occupied by processes to the CPU of the entire system cannot be accurately reflected. The % CPU column in the top output is the percentage of CPU time occupied by the process to the CPU of the entire system. It is used to limit the CPU usage of the process to a more reasonable value, the % MEM column also reflects the percentage of memory occupied by processes, which can be used to limit the memory usage of processes. The shell script code is as follows:
For PID in $ PIDS
Do
Renice + 10 $ PID
Echo "renice + 10 $ PID"
Done
You can run this script in cron. For example, you only need to add the crontab entry as root when checking every minute:
# Crontab-e
* ***** Limit. sh
In the next minute, the system checks the nice values of processes that occupy more than 50% of the CPU or 25% of the memory. This lowers the priority of such processes and reduces the chances of being scheduled, at the same time, an email is sent to the root, prompting that the process has been adjusted.
However, it is best to use PAM to restrict memory usage. RedHat can be set in/etc/security/limits. conf.
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