Recipe 6.1. Setting the Priority of a ProcessProblemYou want to raise or lower the priority of a process. This is beneficial if you want to boost a CPU-starved process or limit a process that is hogging the CPU. SolutionUsing a graphical user interface
You can also accomplish the same task using the Sysinternals Process Explorer (procexp.exe) tool: right-click on the process and select Set Priority. Using a command-line interfaceWith the start command, you can set the priority of a process when you initially run it. The following example shows how to create a process with a high priority: > start /HIGH <ProgramPath> The other valid priority options include /LOW, /NORMAL, /REALTIME, /ABOVENORMAL, and /BELOWNORMAL. Using VBScript' This code sets the priority of a process Const NORMAL = 32 Const IDLE = 64 Const HIGH_PRIORITY = 128 Const REALTIME = 256 Const BELOW_NORMAL = 16384 Const ABOVE_NORMAL = 32768 ' ------ SCRIPT CONFIGURATION ------ strComputer = "." intPID = 3280 ' set this to the PID of the target process intPriority = ABOVE_NORMAL ' Set this to one of the constants above ' ------ END CONFIGURATION --------- WScript.Echo "Process PID: " & intPID set objWMIProcess = GetObject("winmgmts:\\" & strComputer & _ "\root\cimv2:Win32_Process.Handle='" & intPID & "'") WScript.Echo "Process name: " & objWMIProcess.Name intRC = objWMIProcess.SetPriority(intPriority) if intRC = 0 Then Wscript.Echo "Successfully set priority." else Wscript.Echo "Could not set priority. Error code: " & intRC end if DiscussionWindows 2000 and Windows Server 2003 use a priority-driven, preemptive scheduling system. This means that processes are given priorities and those with higher priorities get more CPU time and subsequently, run quicker. This is useful for administrators to know because in certain situations, it can be advantageous to play with the priorities of processes to get the desired result from your system. For example, if you find a process that is pegging the CPU on a system, if you are able to run Task Manager, you can lower the priority of that process, which should help you launch other processes or applications to diagnose and troubleshoot the badly behaving process. Another way to tackle this problem is to suspend the process, which I describe in Recipe 6.2. Windows supports six priority classes. The following is a list of the classes and their corresponding numeric value:
To view the current priority of all processes, run the following command: > wmic process get name,processid,priority You can also see the priority of processes in pslist output (the Pri column). See AlsoRecipe 6.2, MS KB 110853 (PRB: Can't Increase Process Priority), and MS KB 193846 (HOWTO: Modify the Process Priority of a Shelled Application) |