Changing Process Priority

With the relation flags in CreateProcess, the parent can assign one of four base priority classes to a new process:

The default priority class is NORMAL_PRIORITY_CLASS. Do not use HIGH_PRIORITY_CLASS, and especially not REALTIME_PRIORITY_CLASS, unless you must. Both levels impair the performance of lower-priority processes. Programs that do run at higher priorities should do so only for short periods of time.

Here are the functions to find out and modify a process’s priority class:

DWORD GetPriorityClass( HANDLE hProcess );
BOOL SetPriorityClass(
   HANDLE hProcess,            // process to modify
   DWORD fdwPriority );        // new priority class

The DWORD values in both functions should be one of the four PRIORITY_CLASS flags just listed. The priority class of a process becomes the base priority for all its threads. Refer to the discussion of thread priorities in Chapter 14 to see how the base priority influences a thread’s dynamic priority.

© 1998 SYBEX Inc. All rights reserved.