[Previous]
[Contents]
[Next]

sched_setscheduler()

change the priority and scheduling policy of a process

Synopsis:

#include <sys/sched.h>
int sched_setscheduler( 
        pid_t pid, int policy,
        struct sched_param *param );

Description:

The sched_setscheduler() function changes the priority of process pid (or the current process if pid is zero) to that of the sched_priority member in the sched_param structure passed as param, and the scheduling policy is set to policy.

The policy parameter must be one of:

SCHED_FIFO
A fixed-priority scheduler in which the highest priority, ready process will run until it blocks or is preempted by a higher priority process.
SCHED_RR
The same as SCHED_FIFO, except processes at the same priority level will time-slice (round robin).
SCHED_OTHER
A general time-sharing algorithm in which a process will decay in priority by 1 if it consumes its timeslice. It will revert back to its default priority when it blocks.

The sched_priority member in param must lie between the minimum and maximum values defined in <sys/sched.h> .

By default, process priority and scheduling algorithm are inherited from or explicitly set by the parent process. Once running, the child process may change its priority using this function.

Returns:

The previous scheduling policy. On error, -1 is returned and errno is set.

Errors:

EINVAL
The priority or scheduling policy isn't a valid value.
EPERM
The calling process doesn't have sufficient privilege to set the priority.
ESRCH
The process pid doesn't exist.

Examples:

See qnx_scheduler().

Classification:

POSIX 1003.4

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, getprio(), qnx_scheduler(), sched_getparam(), sched_getscheduler(), sched_setparam(), sched_yield(), setprio()


[Previous]
[Contents]
[Next]