Process priorities. Priorities in Windows


let's talk about priorities Windows processes . In most cases, there is no need to “play” with setting priorities, but sometimes a competent System Administrator can help the system more correctly distribute processor time between running tasks. There is no single recipe, but by “selection and search” it is quite feasible. Where might this be needed? For example, in the 1C-SQL combination, you can give more processor time to 1C and SQL, as the most resource-critical processes.

In general, look and change the priority running process possible through Task Manager

WindowsNT/2000/7 /2008

On Windows 2012 it was “buried” a little deeper

As can be seen from the above examples, only 6 priorities are available to you (as it turns out later, these are priority classes). Enough? Microsoft thinks so. But let's remember the “legendary” phrase of Bill Geist, who said that “640 KB of RAM will be enough for everyone.” But time has shown that this is far from the case. :)

Now let's figure out how it really is.

There are actually 32 priority levels in Windows, from 0 to 31.

They are grouped like this:

  • 31 — 16 real time levels;
  • 15 — 1 dynamic levels;
  • 0 system level, reserved for the zero-page thread.

When a process is created, it is assigned one of six priority classes:

  1. Real time class (value 24),
  2. High class (value 13),
  3. Above normal class (value 10),
  4. Normal class (value 8),
  5. Below normal class (value 6),
  6. or Idle class (value 4).

You can view the process priority, as described above, using Task Manager.

Note: Above normal and Below normal priorities have been introduced since Windows 2000.

Priority of each thread ( base thread priority) consists of the priority of its process and relative priority the stream itself. There are seven relative thread priorities:

  1. Normal: same as the process;
  2. Above normal : +1 to process priority;
  3. Below normal : -1;
  4. Highest: +2;
  5. Lowest: -2;
  6. Time critical: sets the base thread priority for the Real time class to 31, for other classes to 15.
  7. Idle: sets the base thread priority for the Real time class to 16, for other classes to 1.

The following table shows the process, relative, and base thread priorities.

Thread priority Process class Process class
Idle class Below normal class Normal class Above normal class High class Real time class
1 IdleIdleIdleIdleIdle
2 Lowest
3 Below…
4 Idle class NormalLowest
5 Above...Below…
6 Below normal class HighestNormalLowest
7 Above...Below…
8 Normal class HighestNormalLowest
9 Above...Below…
10 Above normal class HighestNormal
11 Above...Lowest
12 HighestBelow…
13 High class Normal
14 Above...
15 Highest
15 Time criticalTime criticalTime criticalTime criticalTime critical
16 Idle
17
18
19
20
21
22 Lowest
23 Below…
24 Real time class Normal
25 Above...
26 Highest
27
28
29
30
31 Time critical

Now that we know all this, what can we do about it all? Well, for example, start using.

How else can you run a process with a “non-standard” priority or change it?

Method 1. Launch a task/process and change the priority through Task Manager.

Disadvantages of the method:

  • Only 6 priorities available
  • Switching priorities is done with the mouse and is not automated.

Method 2. You can use the START command with the appropriate keys

The available priority keys are as follows (I'm deliberately omitting the keys command line teams START not related to the described process of working with priorities):

C:\>start /?
Starts a separate window to run a specified program or command.
START ["title"]


LOW Start application in the IDLE priority class.
NORMAL Start application in the NORMAL priority class.
HIGH Start application in the HIGH priority class.
REALTIME Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.

As you can see, the START command makes it possible to start a process with the same 6 priorities that are available through Task Manager

Disadvantage of the method:

  • Only 6 priorities available

Method 3: Using the wmic.exe utility

As shown above, Task Manager and the START command are quite clunky for the task of assigning priorities. Let's see how to use this more flexibly. We will use the utility wmic.exe.

Command line:

wmic process where name="AppName" CALL setpriority ProcessIDLevel

wmic process where name="calc.exe" CALL setpriority 32768

wmic process where name="calc.exe" CALL setpriority "above normal"

Priorities (predefined):

  • idle: 64
  • below normal: 16384
  • normal: 32
  • above normal: 32768
  • high priority: 128
  • real time: 256

Retreat. What to do if there are several processes of the same name? The priority of a process can be changed either by the process name or by using the PID (Process ID) of the process.

Here's a short example of running wmic.exe to get the information you need

We use the command:

Note: I will not give an example of executing this command. Too much big list processes turns out. You can do this yourself, if you wish.

You will get a list of processes running on your local computer. Now run the command:

wmic process list brief | find "cmd.exe"

Result:

I specially launched several copies of cmd.exe to make the illustration more complete.

Now the list of processes is limited only to those processes whose executable module name contains the string “cmd.exe”. pay attention to Process PID(s).

Now let's try to select the processes we are interested in using WMI directly and without resorting to standard means command line. To do this, simply write:

wmic process where description="cmd.exe" list brief

Result:

Compare your results. Remember the PID of the CMD.EXE process.

Command line to run wmic.exe

wmic process where processid="XXXX" CALL setpriority ProcessIDLevel

Well, now we can change the priority of a specific process (for example, with PID=8476):

wmic process where processid="8476" CALL setpriority 32768

wmic process where processid="8476" CALL setpriority "above normal"

Most versions of UNIX use priority levels from 0 to 127. For the sake of precision, we will assume that 0 is the highest priority, although in some versions the opposite is true.

The entire range of priorities is divided into top part(kernel mode priorities) and the lower part (task mode priorities). This division is shown in Fig. 4‑3.

The current (dynamic) priority of a process running in task mode is determined by the sum of three terms: the base value, the relative priority of this process, and the “penalty” for intensive use of processor time.

The base priority value is the default value that the system assigns to a new process when it is created. In many versions of UNIX base value equals the task's highest priority + 20.

Relative priority, which for some reason is called in UNIX " nice number " is assigned to the process when it is created. By default, the system sets the relative priority value of zero for a process. Regular user can only increase this value (i.e. lower the priority of a process), and a privileged user can decrease it up to the highest priority of the task (for the highest priority processes). When a new process is created, it inherits the relative priority of its parent.

The CPU penalty for a running process increases with each timer interrupt. As a result, a high-priority process will not be able to monopolize CPU usage and will have to cede time slices to low-priority processes from time to time. However, the system is “not vindictive”: every second, the fines accumulated by the processes are reduced by half. Thus, a process removed from the processor will restore its original priority after some time.

The active task with the highest priority is always selected for execution, and if there are several of them, they receive time slices in a round-robin manner.

Kernel priorities have a completely different meaning. As we know, processes running in kernel mode cannot be preempted, and therefore priorities do not matter to them. Kernel priorities are set only for sleeping processes and depend only on the reason for sleep. In some cases, the same event causes multiple processes to wake up at once. In this case, the one whose kernel priority is higher starts working first. The kernel priority distribution is designed in such a way that those that finish first system calls, which most block the use of scarce resources.

The kernel priority range is divided into two parts depending on how sleeping processes react to receiving a signal. In a state of “high priority” sleep, usually associated with disk operations, the process ignores incoming signals because processing them would delay the response to an expected important event. If a process “sleeps at low priority”, waiting for a non-urgent and perhaps not immediate event (for example, a user pressing a key), then it can wake up when it receives a signal and process this signal.

| Next page

Process priority determines how often this process, compared to other processes queued for execution on the processor, will be executed by the processor.

You must understand that priority is a relative concept. After all, in this moment There may be twenty processes in the execution queue, and two in the next one. Therefore, priority is a “floating” value that is determined by the system itself depending on the current situation.

On Linux, the priority value can be a number in the range of forty values. How vague I expressed myself. Actually, it all depends on the version Linux kernels. The priority value can range from -20 to 19 or from 0 to 39. In both cases, the possible value is limited to forty numbers. In 2.6.x kernels, the priority value ranges from 0 to 39.

The lower the number, the higher the priority of the process. That is, a process with priority 5 has higher priority than a process with priority 16.

You cannot directly change the priority of a process, that is the prerogative operating system. But you can determine how much more or less the system will “like” the process. To do this, use the nice field. That is, to change the priority, the administrator must change the value of the nice field. If the nice value is zero, it means that the program's priority has not been changed. If the nice field is written a negative number– process priority is increased, positive - decreased.

Let's look at the corresponding fields shown by the program:

$ ps -t pts/1 -o pid,pri,ni,comm PID PRI NI COMMAND 4205 24 0 bash 4246 24 0 ps $

As you can see from the example, programs running on the pts/1 terminal have the nice field value equal to zero. Consequently, these programs are executed with the standard priority set by the system itself.

IN following example programs with increased priority that are currently running in the system will be shown ( As an example, I wanted to use the ps program “ps -e -o pid,pri,ni,comm”, but for some reason the priority field value was not displayed correctly. There is no perfection in the world. Therefore, I had to use top in command mode.)

$ top -b -n1 | grep "\-." | sed -e "1d" 3 root 10 -5 0 0 0 S 0.0 0.0 0:00.04 events/0 4 root 10 -5 0 0 0 S 0.0 0.0 0:00.01 khelper 5 root 10 -5 0 0 0 S 0.0 0.0 0 aio /0 147 root 12 -5 0 0 0 S 0.0 0.0 0:00.00 xfslogd/0 148 root 12 -5 0 0 0 S 0.0 0.0 0:00.00 xfsdatad/0 871 root 12 -4 1472 456 384 S 0.0 0.2 0:00.02 udevd 1506 root 10 -5 0 0 0 S 0.0 0.0 0:00.07 ipw2100/0 $

As you can see, there are quite a lot of such programs.

Any user of the system can change the value of the nice field. But there are two restrictions:

  • The user can change the priority only of programs running with his rights.
  • The user can only lower the priority (write a positive number in the nice field).

As usual, the superuser can do everything! It can change the priority of any process in the system, it can decrease and increase priorities.

To change the priority, you can use the top program. First, we get a list of all processes performed by user1. For brevity, I will remove the top header.

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME #C COMMAND 4316 user1 15 0 3332 1944 1192 S 0.0 0.8 0:00 0 bash 4326 user1 16 0 2064 1060 832 R 0.0 0.4 0:00 0 top

To change the priority of a process, use the r command.

PID to renice: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME #C COMMAND 4326 user1 16 0 2064 1060 832 R 0.3 0.4 0:00 0 top 4316 user1 15 0 3332 1944 1192 S 0.0 0.8 0:00 0 bash

The program will ask you to enter the PID of the process whose priority should be changed. Enter PID and press Enter.

Renice PID 4326 to value: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME #C COMMAND 4326 user1 16 0 2064 1060 832 R 0.3 0.4 0:00 0 top 4316 user1 15 0 3332 1944 1192 S 0.0 0.8 0:00 0 bash

Now the program asks you to enter a value that will be written in the nice field. Enter the number 10 and press Enter.

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME #C COMMAND 4316 user1 15 0 3332 1944 1192 S 0.0 0.8 0:00 0 bash 4326 user1 26 10 2064 1060 832 R 0.0 0.4 0:00 0 top

The value of the nice field has changed to 10. The value of the process priority field has changed accordingly.

There are two other programs that can be used to change the priority:

UID, EUID, GID, EGID

UID(User ID) is the identifier of the user who created this process, more precisely, a copy of the UID value of the parent process. Only its creator (owner) and the root user can change the attributes of a process.

The UID is a 32-bit integer, but for compatibility purposes it is recommended that it not exceed a maximum of 16-bit signed integer (32767).

EUID Effective User ID is the effective, or current, user ID of a process, intended to determine which resources and files a process is currently authorized to access. Most processes have the same UID and EUID values.

UID and EUID allow you to distinguish between the concepts of personification and access rights. EU1D can be set and reset to grant or remove additional privileges to a process.

GID(Group ID) is the identifier of the group to which the process owner belongs.

Effective Group ID EGID) is related to the GID attribute in the same way that an EUID value is related to a UID.

The order of processes is determined by a special system process - task scheduler.

Typically, in Linux systems, the execution of a particular process is determined by priority and its inverse value - the compliance factor.

A priority process determines how much CPU time a program receives. The kernel uses a dynamic priority calculation algorithm that takes into account how much CPU time a process has already used and how long it has been waiting for its turn.

Compliance Factor is the number by which the kernel determines its policy regarding processes competing for access to central processor. The higher the compliance factor, the lower the priority of the process, and vice versa. A low or negative value means high priority is being used: the process is not being very compliant. Range acceptable values- from -20 to +19. Default is 0.

Unless the user takes special action, the child process inherits the priority of its parent process. The process owner can increase the compliance factor, but cannot decrease it, even to return to the standard value. This prevents low priority processes from spawning high priority children. The superuser can set arbitrary compliance factor values.

The compliance factor can be set when creating the process. This is done using the nice command. The renice command allows you to change the priority of a running process.







2024 gtavrl.ru.