Objective:
VPS universality is not high, many people may have such a feeling, in the implementation of DU, tar and other commands, will cause the system load soared, Apache response slow. This can be mitigated by the nice command changing the process priority. The nice command adjusts the priority of the process in the Linux system.
In layman's words, the process has 19 to 19 of these 39 priorities in a Linux system. -19 top priority, 19 least priority. The default priority for a process is 0. Set the nice value of the process to 19 if you want the process to be the highest priority, or set it to 19 if you want the least amount of system CPU time for the process to take the least precedence.
1. Create a new process and set the priority
Package The documents directory under the current directory, but do not want tar to consume too much CPU:
1 |
nice -19 tar -zcf pack. tar .gz documents |
The method is very simple, which is to add "nice-19" before the original command. Many people may have doubts, the lowest priority is not 19? That's because the "-" in this "-19" represents only the parameter prefixes, so if you want to:
Package The documents directory under the current directory and give the TAR process the highest priority:
1 |
nice --19 tar -zcf pack. tar .gz documents |
2. Change the priority of a process that already exists
Set the PID 1799 process priority to the lowest (19):
Set the PID 1799 process priority to the highest (-19):
It is likely to be found that the Renice command is in the opposite form of the nice command's precedence parameter. Direct priority as a parameter, you can not add the "-" number, this requires beginners attention.
3. View process Priorities
Use the top command directly to view process priorities.
The role of Linux for process priority adjustment is very obvious, in the actual operation can also be clearly realized.
The nice command for Linux to change process priorities