Name

getpriority, setpriority
- get/set program scheduling priority

Library

libc.lib

Synopsis

  #include <sys/time.h>
  #include <sys/resource.h>
  int getpriority (int which, int who);
  int setpriority (int which, int who, int prio);

Return values

Since getpriority can legitimately return the value -1, it is necessary to clear the external variable errno prior to the call, then check it afterward to determine if a -1 is an error or a legitimate value.

The setpriority returns 0 on success and -1 on error with the errno set.


Detailed description

The scheduling priority of the process, process group, or user, as indicated by which and who is obtained with the getpriority system call and set with the setpriority system call. The which argument is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and who is interpreted relative to which (a process identifier for PRIO_PROCESS, process group identifier for PRIO_PGRP, and a user ID for PRIO_USER ). A zero value of who denotes the current process, process group, or user. The prio argument is a value in the range -20 to 20. The default priority is 0; lower priorities cause more favorable scheduling.

If the prio is greater than the greatest priority supported, it is set to the greatest priority supported. If the prio is lesser than the least priority supported, it is set to the least priority supported.


Examples

#include<sys/resource.h>        
#include<unistd.h>
#include<stdio.h>
int test_getpriority()
{
   int retVal;
   errno = 0;
   retVal = getpriority(PRIO_PROCESS, 0);
   if((retVal == -1) && (errno == ENOSYS))
   {
      printf("Failed");
      return -1;
   }
   else
   {
      printf("getpriority passed");
      printf("\npriority = %d ", retVal);
   }    
   return 0;
}

         

Output

getpriority passed
priority = 0

         

#include<sys/resource.h>        
#include<unistd.h>
#include<stdio.h>
int test_setpriority()
{
   int retVal;
   errno = 0;
   retVal = setpriority(PRIO_PROCESS, 0, 0);
  
   if((retVal == -1) && (errno == ENOSYS))
   {
      printf(“Failed”);
      return -1;
   }
   else
   {
      printf("Setpriority passed");
      printf("\n getpriority now: %d", getpriority(PRIO_PROCESS,0))
    }   
   return 0;
}

         

Output

Setpriority passed
getpriority now: 0

         

Limitations

1. The values PRIO_PGRP and PRIO_USER for the which and any value other than 0 for who are not supported, when given return ENOSYS.

2. To effectively increase or decrease the priority of the process, one should consider the following:
        Highest                                                                 -16 to -20
        Above Normal                                                     -6 to -15
        Normal                                                               +4 to -5
        Below Normal                                                    +14 to +5
        Lowest                                                           +20 to +15

3. The setting of the priority to values -16 to -20 is not supported, the use of which sets errno to EINVAL.


Errors

[ENOSYS] -> The which argument was one of PRIO_PGRP, or PRIO_USER. and/or who was other than 0.

[EINVAL] ->The process tried to set the priority to a value from among -16 to -20.


See also

nice

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top