sched_setparam Subroutine

Purpose

Sets scheduling parameters.

Library

Standard C Library (libc.a)

Syntax

#include <sched.h>

int sched_setparam (pid, param)
pid_t pid;
const struct sched_param *param; 

Description

The sched_setparam subroutine sets the scheduling parameters of the process specified by the pid parameter to the values specified by the sched_param structure pointed to by the param parameter. The value of the sched_priority member in the sched_param structure is any integer within the inclusive priority range for the current scheduling policy. Higher numerical values for the priority represent higher priorities.

If a process specified by the pid parameter exists, and if the calling process has permission, the scheduling parameters are set for the process whose process ID is equal to the value of the pid parameter.

If the pid parameter is zero, the scheduling parameters are set for the calling process.

If the caller is favoring a process, it must have SET_PROC_RAC authority. The caller should have the same effective or real user id or BYPASS_DAC_WRITE authority to modify the priority of the process.

Implementations may require the requesting process to have the appropriate authority to set its own scheduling parameters or those of another process.

The target process, whether it is running or not running, is moved to the end of the thread list for its priority.

If the priority of the process specified by the pid parameter is set higher than that of the lowest priority running process and if the specified process is ready to run, the process specified by the pid parameter preempts the lowest priority running process. Similarly, if the process calling the sched_setparam subroutine sets its own priority lower than that of one or more other non-empty process lists, the process that is the head of the highest priority list also preempts the calling process. Thus, the originating process might not receive notification of the completion of the requested priority change until the higher priority process has executed.

Other scheduling policies (such as, SCHED_FIFO2, SCHED_FIFO3, SCHED_FIFO4) behave like fixed priority scheduling policies (such as, SCHED_FIFO and SCHED_RR).

The effect of the sched_setparam subroutine on individual threads is dependent on the scheduling contention scope of the threads:
  • The sched_setparam subroutine has no effect on the scheduling of threads with system scheduling contention scope.
  • For threads with process scheduling contention scope, the threads' scheduling parameters are not affected. However, the scheduling of these threads with respect to threads in other processes may be dependent on the scheduling parameters of their process, which are governed using the sched_setparam subroutine.

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 the sched_setparam subroutine.

The underlying kernel-scheduled entities for the process contention scope threads will have their scheduling parameters changed to the value specified in the param parameter. Kernel-scheduled entities for use by process contention scope threads created after this call completes inherit their scheduling policy and associated scheduling parameters from the process.

The sched_setparam subroutine is not atomic with respect to other threads in the process. Threads might continue to execute while this subroutine call is in the process of changing the scheduling policy for the underlying kernel-scheduled entities.

Parameters

Item Description
pid Specifies the process for which the scheduling parameter is set.
param Points to the sched_param structure.

Return Values

If successful, the sched_setparam subroutine returns zero.

If the sched_setparam subroutine is unsuccessful, the priority remains unchanged, and the subroutine returns a value of -1 and sets errno to indicate the error.

Error Codes

The sched_setparam subroutine fails if:
Item Description
EINVAL One or more of the requested scheduling parameters is outside the range defined for the scheduling policy of the specified process ID.
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 the scheduling parameters for the specified process, or does not have the appropriate authority to invoke the sched_setparam subroutine.
ESRCH The pid parameter is negative, or no process can be found that corresponds to the one specified by the pid parameter.