Why are virtue values ​​inversely related to process priority?

The niceness of the process decreases with increasing priority of the process.

Extract from Linux 4 th Edition programming, p. 169:

By default, priority is 0. Positive priorities are used to background tasks that are executed when another task with a higher priority is not ready to start. Negative priorities make the program work more often, taking a large share of the available processor time. The range of valid priorities is from -20 to +20. This is often confusing, because the higher the numerical value, the lower the priority of execution.

Is there any particular reason for negative values ​​corresponding to a higher process priority (as opposed to increasing priority for processes with a higher cost)?

+7
source share
4 answers

Hysterical reasons - I mean historical ... I am pretty sure that it started with numbers rising from 0 .. 20, and the lowest available was taken first. Then someone came to the conclusion that "Hmm, that if we need to make something MORE important," we should go negatively.

You want the priority to be a sortable value, so if you start with "the default is zero", you must either make a higher priority a larger number (but "priority 1" in a daily conversation is higher than "priority 2" - when your boss says : “Make it your number one priority,” which means it's important, right?). Being a computer, obviously priority 0 is above priority 1, and priority -1 is above priority 0.

In the end, it is an arbitrary choice. Perhaps Ken Thomson, Dennis Ritchie or one of these guys will be able to say exactly why they choose this particular sequence, and not 0..255, for example.

+2
source

First of all, the answer is a little long, but it is only for clarification.

As with the linux kernel, every regular process can have priorities called static priority, from 100 (highest) to 139 (lowest). therefore, there are basically 40 priorities that can be assigned to a process.

therefore, when any process is created, it gets the priority of the parent, but if the user wants to change its priority, this can be done using the nice (nice_value) system call.

& the reason for your question is that every process wants a base time quantum, which is used as the time during which the process will receive the processor to execute it in milliseconds, and this is calculated as

time={ if static_priority<120 (140-static_priority)*20 if static_priority>=120 (140-static_priority)*5 

, so the sys_nice () service service processes the nice () system call. Although nice_value can have any value, absolute values ​​in excess of 40 are reduced to 40. Traditionally, negative values ​​correspond to requests for priority increments and require superuser privileges, while positive values ​​correspond to requests for lowering priorities. If nice_value is negative, the function calls able () to check if the process has the CAP_SYS_NICE capability. In addition, the function calls hook_task_setnice () hook. , therefore, at the end, nice_value is used to calculate the static priority, and then this static priority is used to calculate the base time quantum.

, therefore, it is clear that to increase the priority, the -ve values ​​are used, therefore, access to the priority requires superuser access, and the values ​​+ ve are used to decrease the priority, so there is no need for superuser access.

+2
source

@ Ewald's answer is correct, as confirmed by Jerry Peak et al. In Unix Power Tools (O'Reilly, 2007, p. 507):

That's why a nice number is usually called pleasant: working with a high share is very kind to users of your system (i.e., working with low priority), while working with a little love teaches the CPU. The term "pleasantness" is inconvenient, as the system of priorities itself. Unfortunately, this is the only term that is accurate (good numbers are used to calculate priorities, but are not priorities themselves) and avoid horrible circuits ("increasing priority means lowering priority ...").

Nice had that meaning, at least the V6 Unix , but the V6 manual never explains it explicitly. Valid values ​​range from -220 to +20, and negative numbers are reserved for the superuser. The range has been changed from -20 to +20 in V7 .

+2
source

Yes - it gets NICER as the number increases and MEANER as the number decreases. Thus, a process is seen as “friendlier” when it does not take all the resources and is “nasty” because it becomes more greedy with resources.

Think of it as “pleasant” moments — the better you relate to others, the more points you have.

+1
source

All Articles