Sets the scheduling policy and parameters.
Standard C Library (libc.a)
#include <sched.h>
int sched_setscheduler (pid, policy, param)
pid_t pid;
int policy;
const struct sched_param *param;
The sched_setscheduler subroutine sets the scheduling policy and scheduling parameters of the process specified by the pid parameter to the policy parameter and the parameters specified in the sched_param structure pointed to by param, respectively. The value of the sched_priority member in the sched_param structure is any integer within the inclusive priority range for the scheduling policy.
The possible values for the policy parameter are defined in the sched.h header file.
If a process specified by the pid parameter exists, and if the calling process has permission, the scheduling policy and scheduling parameters are set for the process.
If the pid parameter is zero, the scheduling policy and scheduling parameters are set for the calling process.
In order to change a scheduling policy to a fixed priority scheduling policy, the caller must have SET_PROC_RAC authority. When changing the scheduling policy to the SCHED_OTHER scheduling policy, if the former policy was not SCHED_OTHER, the caller must have SET_PROC_RAC authority.
The sched_setscheduler subroutine is successful if it succeeds in setting the scheduling policy and scheduling parameters of the process specified by pid to the values specified by the policy parameter and the structure pointed to by the param parameter, respectively.
If an implementation supports a two-level scheduling model in which library threads are multiplexed on top of several kernel-scheduled entities, the underlying kernel-scheduled entities for the system contention scope threads are not affected by these subroutines.
The underlying kernel-scheduled entities for the process contention scope threads have their scheduling policy and associated scheduling parameters changed to the values specified in the policy and param parameters, respectively. Kernel-scheduled entities for use by process contention scope threads that are created after this call completes inherit their scheduling policy and associated scheduling parameters from the process.
This subroutine is not atomic with respect to other threads in the process. Threads may continue to execute while this subroutine is in the process of changing the scheduling policy and associated scheduling parameters for the underlying kernel-scheduled entities used by the process contention scope threads.
Item | Description |
---|---|
pid | Specifies the process for which the scheduling policy and parameters are set. |
policy | Contains the scheduling policy and scheduling parameters settings. |
param | Points to the sched_param structure. |
Upon successful completion, the sched_setscheduler subroutine returns the former scheduling policy of the specified process. If the sched_setscheduler subroutine fails to complete successfully, the policy and scheduling parameters will remain unchanged, and the subroutine returns -1 and sets errno to indicate the error.
Item | Description |
---|---|
EINVAL | The param parameter is null or a bad address. |
ENOTSUP | This interface does not support processes capable of checkpoint. |
EPERM | The requesting process does not have permission to set either or both of the scheduling parameters or the scheduling policy of the specified process. |
ESRCH | The pid parameter is negative, or no process can be found that corresponds to the one specified by the pid parameter. |