Jump to content

DosSetPriority: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==Description==
Changes the base priority of a child process or thread in the current process.
Changes the base priority of a child process or thread in the current process.


==Syntax==
==Syntax==
<PRE>
DosSetPriority(scope, ulClass, delta, PorTid)
#define INCL_DOSPROCESS
#include <os2.h>


ULONG    scope;    /*  The extent of the priority change. */
ULONG    ulClass;  /*  Priority class of a process. */
LONG      delta;    /*  Change to apply to the current base priority level of the process. */
ULONG    PorTid;  /*  A process identifier (scope == PRTYS_PROCESS or PRTYS_PROCESSTREE) or a thread identifier (scope == PRTYS_THREAD). */
APIRET    ulrc;    /*  Return Code. */
ulrc = DosSetPriority(scope, ulClass, delta, PorTid);
</PRE>
==Parameters==
==Parameters==
; scope (ULONG) - input : The extent of the priority change.
;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.


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==
==Return Code==
ulrc (APIRET) - returns
;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


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==
==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.
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.  
When a process changes the priority of current or descendant processes, only default priorities are changed.


==Example Code==
==Example Code==
This sample sets the current thread priority to Time Critical level 15. It then uses DosGetInfoBlocks to retrieve the priority.
This sample sets the current thread priority to Time Critical level 15. It then uses DosGetInfoBlocks to retrieve the priority.
<PRE>
<PRE>
#define INCL_DOSPROCESS
#define INCL_DOSPROCESS
Line 111: Line 74:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosEnterCritSec|DosEnterCritSec]]
* [[DosEnterCritSec]]
* [[OS2 API:CPI:DosGetInfoBlocks|DosGetInfoBlocks]]  
* [[DosGetInfoBlocks]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 11:52, 26 June 2021

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;
}

Related Functions