Process CPU resource allocation refers to the priority of the process. High priority processes have priority rights to implementation. Configuring process precedence is useful for Linux in multitasking environments and can improve system performance. The process can also be run to the specified CPU, so that the non-important process to a certain CPU, can greatly improve the overall performance of the system.
First, look at the system process:
PR is the shorthand for priority, and NI is the shorthand for Nice. These two values determine the value of the PR, the smaller the PR, the higher the priority of the process, the more "priority execution". The conversion formula is: PR (new) = PR (old) + NI
---------------------------------------------------------------------------
Second, the command to modify the priority of the process has two main: Nice,renice
1 , the first execution of the program specifies a nice value: Nice
Java code
- Nice-n -5/usr/local/mysql/bin/mysqld_safe &
Linux Nice command details
Function Description: Set priority.
Syntax: Nice [-n < priority level >][--help][--version][execution Instructions]
Additional note: The Nice directive can change the priority level of program execution.
Parameter:-n< priority level > or-< priority level > or--adjustment=< priority > Set priority level for the instruction to be executed. Levels range from 20-19, where-20 is the highest, 19 lowest, and only system administrators can set negative levels.
--help online Help.
--version Displays version information.
---------------------------------------------------------------------------
2.1 , adjust the nice:renice of existing processes
Java code
- Renice-5-P 5200
- #PID为5200的进程nice设为-5
Linux Renice Command detailed
Function Description: Adjust priority.
Syntax: Renice [Priority Level][-G < program group name ...] [-p < Program identification Code, ....] [-u < user name; ...]
Additional note: The Renice directive can readjust the priority level of the program execution. The preset is to adjust its priority with the program identification Code designation program, you can also specify the program group or user name to adjust the priority level, and modify all the programs that belong to the program group or user priority. Level range from -20--19, only system administrators can change the priority of other user programs, and only system administrators can set negative levels.
Parameters
-G < program group name > Use the program group name to modify the priority of all programs that belong to the program group.
-P < Program identification code > change the program's priority level, this parameter is a preset value.
-u < user name > Specify user name, modify the priority of all programs that belong to the user.
2.2 , or you can change the existing process's nice with the top command:
Java code
- Top
- #进入top后按 "R"--input process pid--> Enter Nice value
---------------------------------------------------------------------------
Third, run the process to the specified CPU (i.e. "CPU affinity" of the modification process): Taskset
two noun (n)
SMP (symmetrical multi-processing): Refers to the aggregation of a set of processors (multi-CPU) on a single computer, sharing the memory subsystem and the bus structure between CPUs. [More ...]
CPU affinity: Chinese calls "CPU affinity", which refers to the ability to bind one or more processes to one or more processors under the CMP architecture. [More ...]
Please first determine your CPU core and naming (e.g. four cores: 0,1,2,3): Cat/proc/cpuinfo
Java code
- TASKSET-CP 1 5200
- #把PID为5200的进程运行到CPU # # on
- #也可以在启动进程时指定:
- Taskset-c 1/etc/init.d/mysql Start
Linux taskset Command detailed
Synopsis
taskset [Options] [mask | list] [PID | command [ARG] ...]
OPTIONS
-P,--pid
operate on the existing PID and not launch a new task
-C,--cpu-list
Specifiy a numerical list of processors instead of a bitmask.
The list may contain multiple items, separated by comma, and
Ranges. For example, 0,5,7,9-11.
-H,--help
Display usage information and exit
-V,--version
Output version information and exit
Linux Process CPU Resource allocation command Nice,renice,taskset