Using the top or PS command will output PRI/PR, NI,%ni/%nice These three indicator values, what exactly is this thing? The approximate explanation is as follows:
PRI: Process priority, which represents the priority that the process can be executed, the smaller the value, the higher the priority, and the sooner it is executed
NI: Process Nice value, which represents the priority value of this process
%nice: The percentage of CPU that has changed the priority of the process (oh, this sentence is very difficult to understand is it, do not hurry slowly to ^_^)
The PRI is well understood, that is, the priority of the process, or the popular point is that the program is executed by the CPU order, the smaller the value of the process of higher priority. What about NI? That's what we're talking about. The nice value, which represents the corrected value of the priority that the process can be executed . As mentioned earlier, the smaller the PRI value, the faster it is executed, then the addition of the Nice value will make the PRI:pri (new) =pri (old) +nice. As a result, the PR is sorted according to Nice, the rule is nice smaller PR (small, more priority), that its priority will be higher, the faster it is executed. If Nice is the same, the process UID is root with greater precedence.
In a Linux system, the nice value ranges from 20 to +19(different system value ranges are not the same), positive values indicate low priority, negative values are high priority, and a value of zero indicates that the process priority is not adjusted. The program with the highest priority has the lowest nice value, so a value of 20 makes a task very important in a Linux system, and conversely, if the nice of the task is +19, it is a noble, selfless task, Allow all other tasks to enjoy a greater share of the valuable CPU time than yourself, which is what NICE's name means.
A process is assigned a different priority value when it is created, and, as previously stated, the value of Nice is a value that indicates that the process priority value can be corrected, so each process is given a nice value when it is scheduled to execute, so that the system can be based on the resources of the system and the various resource consumption of the specific process. The priority value of the active intervention process. Under normal circumstances, a child process inherits the Nice value of the parent process, such as during system startup, the Init process is given 0, and all other processes inherit the nice value (because the other processes are the child processes of init).
A figurative analogy to the nice value, assuming that in a CPU rotation, there are 2 runnable processes A and B, if their nice values are 0, assuming the kernel assigns each of them 1k CPU time slices. But assuming that process a is 0, but the value of B is-10, then the CPU may assign a and B time slices of 1k and 1.5k, respectively. So it can be understood that the value of nice affects how much the kernel allocates to the process's CPU time slices, the more time slices the process, the higher the priority, the lower its priority value (PRI). %nice, is the percentage of CPU consumed by the process that has changed the priority, as in the example above is 0.5k/2.5k=1/5=20%.
Thus, the process nice value and process priority are not a concept, but the process nice value affects the process's priority change.
The nice value of the process can be modified, and the modified commands are nice and renice.
1. The nice command is to set a nice value to execute the command process, which is in the form nice–n adjustment command Command_option, and the default is 10 if no adjustment is specified here.
2. The Renice command is to set a nice value for a process that is already running, assuming that the nice value of 0,renice is 3 for a running process, then the nice value of this running process is 3.
Note: If a user sets a nice value that exceeds the nice's boundary value (Linux is 20 to +19), the system takes nice's boundary value as the nice value for the process.
Examples are as follows:
For non-root users, only the nice value of the process underneath will be larger and not smaller. If you want to be small, you have to have the appropriate authority.
[Email Protected]_dbc ~]$ Nice
0
[[Email protected]_dbc ~]$ nice-n 3 ls
Agent bin Important_bak logs Statistics_import.log tmp_forum_stats.dmp tmp_taobao_stats.dmp tmp_tbcat_stats.dmp Top.dmp Worksh
[[Email Protected]_dbc ~]$ nice-n-3 ls
Nice:cannot Set Priority:permission denied
For the root user, the child process can be given a smaller nice value.
[Email protected] root]# Nice
0
[[email protected] root]# nice-n-3 ls
192.168.205.191.txt anaconda-ks.cfg clariion.log Desktop disk1 emc.sh file_sort install.log install.log.syslog log OPS RH El_os_soft Root_link_name
Similarly, the execution of Renice must have the appropriate authority to execute.
Process priority, process Nice value and%nice interpretation