DosSetPriority
From EDM2
Changes the base priority of a child process or thread in the current process.
Syntax
DosSetPriority(scope, ulClass, delta, PorTid)
Parameters
- scope (ULONG) - input
- The extent of the priority change.
- The values of this field are shown in the following list:
- 0 PRTYS_PROCESS All the threads of any process.
- 1 PRTYS_PROCESSTREE All the threads of a process and any descendants. The indicated process must be the current process or a process created by the current process. Detached processes may not be specified. The indicated process may have terminated.
- 2 PRTYS_THREAD A single thread of the current process.
- ulClass (ULONG) - input
- Priority class of a process.
- The values of this field are shown in the following list:
- 0 PRTYC_NOCHANGE No change, leave as is
- 1 PRTYC_IDLETIME Idle-time
- 2 PRTYC_REGULAR Regular
- 3 PRTYC_TIMECRITICAL Time-critical
- 4 PRTYC_FOREGROUNDSERVER Fixed high
- delta (LONG) - input
- Change to apply to the current base priority level of the process.
- This value must range from -31 (PRTYD_MINIMUM) to +31 (PRTYD_MAXIMUM).
- PorTid (ULONG) - input
- A process identifier (scope == PRTYS_PROCESS or PRTYS_PROCESSTREE) or a thread identifier (scope == PRTYS_THREAD).
- If this operand is equal to zero, the current process or thread is assumed.
Return Code
- ulrc (APIRET) - returns
- DosSetPriority returns one of the following values:
- 0 NO_ERROR
- 303 ERROR_INVALID_PROCID
- 304 ERROR_INVALID_PDELTA
- 305 ERROR_NOT_DESCENDANT
- 307 ERROR_INVALID_PCLASS
- 308 ERROR_INVALID_SCOPE
- 309 ERROR_INVALID_THREADID
Remarks
DosSetPriority allows a process to change the priority of the current process or a child process, as well as any descendants. It also allows a process to change the priority of a single thread within the current process.
When a process changes the priority of current or descendant processes, only default priorities are changed.
Example Code
This sample sets the current thread priority to Time Critical level 15. It then uses DosGetInfoBlocks to retrieve the priority.
#define INCL_DOSPROCESS #define INCL_DOSERRORS #include <os2.h> #include <stdio.h> int main(VOID) { PTIB ptib = NULL; /* Thread information block structure */ PPIB ppib = NULL; /* Process information block structure */ APIRET rc = NO_ERROR; /* Return code */ rc = DosSetPriority (PRTYS_THREAD, /* Change a single thread */ PRTYC_TIMECRITICAL, /* Time critical class */ 15L, /* Increase by 15 */ 0L); /* Assume current thread */ if (rc != NO_ERROR) { printf ("DosSetPriority error : rc = %u\n", rc); return 1; } else { rc = DosGetInfoBlocks(&ptib, &ppib); if (rc != NO_ERROR) { printf ("DosGetInfoBlocks error : rc = %u\n", rc); return 1; } else { printf("Priority Class = %d\n", ((ptib->tib_ptib2->tib2_ulpri) >> 8) & 0x00FF); printf("Priority Level = %d\n", ((ptib->tib_ptib2->tib2_ulpri) & 0x001F) ); } /* endif */ } return NO_ERROR; }