DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

sched_setparam(S)


sched_setparam -- set scheduling parameters

Syntax

cc . . . -lc

#include <sched.h>

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

Description

sched_setparam sets the scheduling parameters of the process specified by pid to the parameters specified in param.

The sched_param structure contains a sched_priority field which must be an integer within the range of the process's particular scheduling policy. Higher values of sched_priority represent higher priorities. The behavior resulting from setting different priorities will vary between different policies.

If pid is 0, the parameters are set for the calling process.

The target process will resume running after all other processes of higher or the same priority have run as it is placed on the tail of the process list for its newly assigned priority. If the priority of the specified process is higher than that of the lowest priority running process and the specified process is ready to run, the lowest priority running process is preempted, and the specified process will be run. Likewise, if the process calling sched_setparam sets its own priority lower than the priority of another process that is runnable (on the run queue), it will be preempted by that process. The behavior will depend on the scheduling policy for the process.

On MPX systems, if pid specifies a process currently running on a different CPU then the process specified by pid will be taken off the CPU. This is the equivalent of the process specified by pid making a call to sched_yield. The process which made the call to sched_setparam will sleep while this occurs.

Return values

Upon successful completion sched_setparam returns zero. If an error has occurred the priority of the target process will remain unchanged, sched_setparam returns -1, and errno is set to indicate the error.

Diagnostics

If sched_setparam terminates due to an error, it will set errno to one of the following values:

[EINVAL]
One or more of the scheduling parameters specified is out of the range defined for the specified process's scheduling policy.

[ENOSYS]
The function is not supported.

[EPERM]
Either the requesting process does not have the privilege to invoke the function, or it does not have permission to set scheduling parameters for the process specified by pid.

[ESRCH]
The process, specified by pid, does not exist.

Examples

The following example illustrates the use of sched_setparam:
   int pmin, pmax, priority = 36;
   struct sched_param sp;
   ...
   pmin = sched_get_priority_min(SCHED_FIFO);
   pmax = sched_get_priority_max(SCHED_FIFO);
   

if (priority >= pmin && priority <= pmax) { sp.sched_priority = priority; } else { sp.sched_priority = pmin; }

sched_setparam(0, &sp);

Files


/usr/lib/libc.a
linking library

See also

sched_get_priority_max(S), sched_getparam(S), sched_getscheduler(S), sched_rr_get_interval(S), sched_setscheduler(S), sched_yield(S)

Standards conformance

Text reprinted and/or adapted from IEEE Std 1003.1b-1993, IEEE Standard for Information Technology, POSIX Part 1: System Application Program Interface (API) Amendment 1: Realtime Extensions [C Language], copyright © 1993 by the Institute of Electrical and Electronics Engineers, Inc. The IEEE takes no responsibility for and will assume no liability for damages resulting from the reader's misinterpretation of said information resulting from the placement and context in this publication. Information is reproduced with the permission of the IEEE.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003