int sched_setscheduler (
const struct sched_param *param);
The sched_setscheduler function changes the scheduling policy and priority of a process. Changing the scheduling policy and priority ensures that an application can determine more effectively when a process will run.
At runtime, a process starts out with an initial priority of SCHED_PRIO_USER_MAX. A call to either the sched_setparam or sched_setscheduler function can raise or lower the priority of a process. If you raise the priority higher than the initial priority, the new priority becomes the maximum for the process. This higher maximum priority exists for the life of the process or until the priority is set to a new, higher priority through another call to the sched_setparam function. The maximum priority cannot be adjusted downward, but subsequent calls to the sched_setparam or sched_setscheduler functions can specify that a process run at a lower priority.
Three scheduling policies are supported: two fixed priority scheduling policies (SCHED_FIFO and SCHED_RR) and one timesharing policy (SCHED_OTHER). Under a fixed-priority scheduling policy, only the user sets and adjusts process priorities. Under a timesharing scheduling policy, the scheduler automatically adjusts priorities according to system resource usage and other factors.
The scheduling policies supported by the realtime interface are as follows:
Setting priorities, in conjunction with a FIFO scheduling policy, allows a critical process to run as soon as it is ready, for as long as it needs to run because it will preempt other lower priority processes. This behavior is important in situations where scheduling a process must be as fast and as precise as possible.
Use the sched_get_priority_max and sched_get_priority_min functions to determine the maximum and minimum values allowed for each scheduling policy. The value of the priority field in the sched_param structure pointed to by param can be any integer within the inclusive range for the current scheduling policy, as defined in <sched.h>. Higher numerical values for param represent higher priorities.
The scheduling policy of a process is inherited across fork and exec calls.
An application designed for portability must initialize all fields of the sched_param structure before making the function call.
You must have superuser privileges to call the sched_setscheduler function.
On a successful call to sched_setscheduler the former scheduling policy of the process is returned. On an unsuccessful call, a value of -1 is returned and errno is set to indicate that an error occurred and the scheduling policy and parameters of the specified process are unchanged.
The sched_setscheduler function fails under the following conditions:
getpid(2), sched_getparam(3), sched_getscheduler(3), sched_setparam(3) delim off