![]() |
![]() |
![]() |
![]() |
![]() |
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Get the current priority of a process
#include <sched.h>
int sched_getparam( pid_t pid,
struct sched_param *param );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The sched_getparam() function gets the current priority of the process specified by pid, and puts it in the sched_priority member of the sched_param structure pointed to by param.
If pid is zero, the priority of the calling process is returned.
#include <sched.h>
#include <stdio.h>
#define PRIORITY_ADJUSTMENT 5
int main (void)
{
int max_priority;
struct sched_param param;
/* Find out the MAX priority for the FIFO Schedular */
max_priority = sched_get_priority_max(SCHED_FIFO);
/* Find out what the current priority is. */
sched_getparam(0, ¶m);
printf("The assigned priority is %d.\n", param.sched_priority);
printf("The current priority is %d.\n", param.sched_curpriority);
param.sched_priority = ((param.sched_curpriority +
PRIORITY_ADJUSTMENT) <= max_priority) ?
(param.sched_curpriority + PRIORITY_ADJUSTMENT) : -1;
if (param.sched_priority == -1)
{
printf(
"Cannot increase the priority by %d. Try a smaller value\n",
PRIORITY_ADJUSTMENT);
return(0);
}
sched_setscheduler (0, SCHED_FIFO, ¶m);
sched_getparam(0, &qparam);
printf("The newly assigned priority is %d.\n",
param.sched_priority);
printf("The current priority is %d.\n",
param.sched_curpriority);
return(0);
}
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
Currently, the implementation of sched_getparam() isn't 100% POSIX 1003.1-1996. The sched_getparam() function returns the scheduling parameters for thread 1 in the process pid, or for the calling thread if pid is 0.
If you depend on this in new code, it will not be portable. POSIX 1003.1 says sched_getparam() should return -1 and set errno to EPERM in a multithreaded application.
errno, getprio(), sched_get_priority_max(), sched_get_priority_min(), sched_getscheduler(), sched_param, sched_setparam(), sched_setscheduler(), sched_yield(), setprio()
![]() |
![]() |
![]() |
![]() |