- SetPriorityClass function (processthreadsapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Examples
- Изменение приоритета процесса Windows с помощью командной строки
- 4 ответов
- Change Process Priority for running processes using Command line
- How to change the process priority level in Windows 10
- 1] Change the priority in Task Manager
- 2] Set the process priority using PowerShell
- 3] Set the priority level using Command Prompt
- Related Posts
- What is syswow64 vmnat.exe process? Is it a virus?
- What is splwow64.exe process in Windows 10 and Can I disable it?
- System process High Disk or CPU usage on Windows 10
- [email protected]
- Changing Windows process priority via command line
- 5 Answers 5
SetPriorityClass function (processthreadsapi.h)
Sets the priority class for the specified process. This value together with the priority value of each thread of the process determines each thread’s base priority level.
Syntax
Parameters
A handle to the process.
The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights.
The priority class for the process. This parameter can be one of the following values.
Priority | Meaning |
---|---|
ABOVE_NORMAL_PRIORITY_CLASS 0x00008000 | Process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS. |
BELOW_NORMAL_PRIORITY_CLASS 0x00004000 | Process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS. |
HIGH_PRIORITY_CLASS 0x00000080 | Process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time. |
IDLE_PRIORITY_CLASS 0x00000040 | Process whose threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes. |
NORMAL_PRIORITY_CLASS 0x00000020 | Process with no special scheduling needs. |
PROCESS_MODE_BACKGROUND_BEGIN 0x00100000 | Begin background processing mode. The system lowers the resource scheduling priorities of the process (and its threads) so that it can perform background work without significantly affecting activity in the foreground. This value can be specified only if hProcess is a handle to the current process. The function fails if the process is already in background processing mode. Windows ServerВ 2003 and WindowsВ XP:В В This value is not supported. |
PROCESS_MODE_BACKGROUND_END 0x00200000 | End background processing mode. The system restores the resource scheduling priorities of the process (and its threads) as they were before the process entered background processing mode. This value can be specified only if hProcess is a handle to the current process. The function fails if the process is not in background processing mode. Windows ServerВ 2003 and WindowsВ XP:В В This value is not supported. |
REALTIME_PRIORITY_CLASS 0x00000100 | Process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive. |
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
Every thread has a base priority level determined by the thread’s priority value and the priority class of its process. The system uses the base priority level of all executable threads to determine which thread gets the next slice of CPU time. The SetThreadPriority function enables setting the base priority level of a thread relative to the priority class of its process. For more information, see Scheduling Priorities.
The *_PRIORITY_CLASS values affect the CPU scheduling priority of the process. For processes that perform background work such as file I/O, network I/O, or data processing, it is not sufficient to adjust the CPU scheduling priority; even an idle CPU priority process can easily interfere with system responsiveness when it uses the disk and memory. Processes that perform background work should use the PROCESS_MODE_BACKGROUND_BEGIN and PROCESS_MODE_BACKGROUND_END values to adjust their resource scheduling priorities; processes that interact with the user should not use PROCESS_MODE_BACKGROUND_BEGIN.
If a process is in background processing mode, the new threads it creates will also be in background processing mode. When a thread is in background processing mode, it should minimize sharing resources such as critical sections, heaps, and handles with other threads in the process, otherwise priority inversions can occur. If there are threads executing at high priority, a thread in background processing mode may not be scheduled promptly, but it will never be starved.
Each thread can enter background processing mode independently using SetThreadPriority. Do not call SetPriorityClass to enter background processing mode after a thread in the process has called SetThreadPriority to enter background processing mode. After a process ends background processing mode, it resets all threads in the process; however, it is not possible for the process to know which threads were already in background processing mode.
Examples
The following example demonstrates the use of process background mode.
Изменение приоритета процесса Windows с помощью командной строки
Я хочу изменить приоритет процесса Windows с помощью командной строки.
Как я могу это сделать?
4 ответов
синтаксис командной строки:
пример:
приоритет:
- idle: 64 (или»idle»)
- ниже нормы: 16384 (или «ниже нормы»)
- нормальный: 32 (или «обычный»)
- выше нормы: 32768 (или «выше нормы»)
- высокий приоритет: 128 (или «высокий приоритет»)
- Реальное время: 256 (или «в реальном времени»)
вы также можете использовать строковые значения вместо целых (проще запомнить), например:
возможные значения: «праздный», «низкий», «ниже нормы», «нормальный», «выше среднего», «высокий приоритет», «в реальном времени»
PS. Не забывайте кавычки, особенно если в строковом значении используется несколько слов
из командной строки партии я бы просто использовать PowerShell. В этом примере запускается calc.exe, находит свой процесс и настраивает свой класс приоритета на «IDLE», он же LOW:
укажите одно из следующих значений перечисления: » Normal, Idle, High, RealTime, BelowNormal, AboveNormal «
вот то же самое из PowerShell с разделенными линиями:
в дополнение к существующим ответам, вопрос Windows эквивалент ‘nice’ перечисляет еще несколько решений:
- С помощью команда START в командной строке (CMD).
- использование свободного ProcessTamer создать правило .исполняемый это автоматически применяется при каждом запуске этого процесса.
- использование сценария PowerShell здесь.
- С помощью Сценарий VBScript здесь.
кроме того, старый SetPriority утилита все еще может работать, но я не пробовал это в течение многих лет.
некоторые из этих решений могут не работать на системных службах или должны быть Запуск от имени администратора.
Change Process Priority for running processes using Command line
When you run applications in your Windows system, they all share your processor resources to operate. The priority level determines the number of processor resources a running application uses.
Windows applications and processes are prioritized based on the following levels:
- Realtime.
- High.
- Above normal.
- Normal.
- Below normal.
- Low.
The higher up the priority level assigned to the process, the more processor resources it uses; hence, the better the performance of the application using the process.
The Windows system automatically assigns the priority levels to the running processes based, but you can change the level manually. This guide will show you three ways to carry out this operation.
Note that although you can easily set process priorities, it’s only temporary because the process reverts to its default priority level when you close the program or reboot your computer.
How to change the process priority level in Windows 10
There are three ways to change the priority level of processes running on your machine. You can do this using the following methods:
- Change the priority in Task Manager.
- Set the process priority using PowerShell.
- Set the priority level using Command Prompt.
Read on to learn how to carry out the above operations using without running into serious complications.
1] Change the priority in Task Manager
To set the priority in Task ManagerRight-click on the Start button and select Task Manager. Click on the downward-facing arrow at the bottom of the Task Manager screen for More details.
Switch to the Details tab at the top of the window. Here, find the process for which you wish to change its priority and hover on Set priority.
From the context menu, select the priority level for the chosen application or process. You can choose between the given priority levels.
Hit the Change priority button and close the Task Manager.
2] Set the process priority using PowerShell
Unlike in the Task Manager method, PowerShell doesn’t name the priority levels in English terms. Instead, you have to set the priority level using designated IDs.
The table below shows the various priority levels and their corresponding IDs:
Priority Level | Corresponding ID |
Realtime | 256 |
High | 128 |
Above normal | 32768 |
Normal | 32 |
Below normal | 16384 |
Low | 64 |
With that said, follow the steps below to change program/process priority levels using PowerShell.
Press the Windows key and search for PowerShell. Click on the program from the search results.
In the PowerShell window, enter the following command and hit ENTER.
In the command above, replace ProcessName with the name of the process or application for which you wish to change its priority level.
Similarly, change PriorityLevelID to the priority level number.
3] Set the priority level using Command Prompt
Press the Windows key + R combination to bring up the Run dialog box. Here, type in cmd and press ENTER.
In the Command Prompt window, enter the command below and press ENTER.
NOTE: In the above command, replace ProcessName with the name of the process whose priority level you want to change.
Also, performing this operation with this command, like in PowerShell, uses the designated priority level IDs. So, when inputting the command above, be sure to replace PriorityLevelID with the corresponding ID from the table in the previous solution.
If you wish to make use of the actual priority level names as we did in the Task Manager method, you can use the command below.
For this command, remember to also replace ProcessName with the name of the application/process, and PriorityLevelName with the priority level you want to use (Realtime, High, Above normal, Normal, Below Normal, or Low).
Having learned the three ways to set process priority levels in Windows 10, I must warn you against putting programs to the realtime priority level. This lets the process use the maximum amount of resources and will hamper the performance of other applications.
Date: October 4, 2020 Tags: Process
Related Posts
What is syswow64 vmnat.exe process? Is it a virus?
What is splwow64.exe process in Windows 10 and Can I disable it?
System process High Disk or CPU usage on Windows 10
[email protected]
Keshi Ile is a Windows enthusiast who loves to write How-to’s, Gadget & software reviews, and tech tutorials. He has also managed SEO teams that grew businesses from zero traffic to authority status.
Changing Windows process priority via command line
I want to change Windows process priority via command line.
How can I do that?
5 Answers 5
The command line syntax:
Example:
Priority:
- idle: 64 (or «idle»)
- below normal: 16384 (or «below normal»)
- normal: 32 (or «normal»)
- above normal: 32768 (or «above normal»)
- high priority: 128 (or «high priority»)
- real time: 256 (or «realtime»)
A small addition.
You can also use string values instead of integers (easier to memorize) like that:
Possible values: «idle», «low», «below normal», «normal», «above normal», «high priority», «realtime»
PS. Don’t forget the quotes, especially if using multiple words in a string value
From batch command line I would simply use PowerShell. This example starts calc.exe, finds its process and adjusts its priority class to «IDLE», aka LOW:
Specify one of the following enumeration values: » Normal, Idle, High, RealTime, BelowNormal, AboveNormal «
Here is the same thing from PowerShell with split lines:
In addition to existing answers, the question Windows Equivalent of ‘nice’ lists some more solutions:
- Using the command START in the command-prompt (CMD).
- Using the free ProcessTamer to set up a rule on the .exe that is automatically enforced whenever that process is started.
- Using a PowerShell script contained here.
- Using a VBScript script contained here.
Additionally, the old SetPriority utility might still work, but I haven’t tried it for many years now.
Some of these solutions may not work on system services or may need to be Run as Administrator.
I am running Windows 7 64-bit.
The wmic command is not reliable. In my considerable experience, it fails unexpectedly for too many (mostly inexplicable) reasons.
The best possible command, because of its reliability, is the START command. The syntax is very simple (this is the 3-line run command for a batch file):
In my opinion its high degree of reliability stems from the fact that it sets the priority level with which the .exe program is launched, rather than trying to meddle with priority after the program has begun running with a different priority.