"Linux" process priorities, process nice values, and%nice

Source: Internet
Author: User
Tags ranges

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 occupied by the process that has changed the priority.

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 nicevalue 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.

Resources:

[1] http://blog.csdn.net/longdel/article/details/7317511

"Linux" process priorities, process nice values, and%nice

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.