| 1 |
.\" Copyright 1996, Tom Bjorkholm <[email protected]> |
| 2 |
.\" Copyright 1996, Markus Kuhn <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
.\" |
| 7 |
.TH sched_setparam 2 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
sched_setparam, sched_getparam \- set and get scheduling parameters |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <sched.h> |
| 16 |
.P |
| 17 |
.BI "int sched_setparam(pid_t " pid ", const struct sched_param *" param ); |
| 18 |
.BI "int sched_getparam(pid_t " pid ", struct sched_param *" param ); |
| 19 |
.P |
| 20 |
\f[B]struct sched_param { |
| 21 |
... |
| 22 |
int \f[I]sched_priority\f[]; |
| 23 |
... |
| 24 |
};\f[] |
| 25 |
.fi |
| 26 |
.SH DESCRIPTION |
| 27 |
.BR sched_setparam () |
| 28 |
sets the scheduling parameters associated with the scheduling policy |
| 29 |
for the thread whose thread ID is specified in |
| 30 |
.IR pid . |
| 31 |
If |
| 32 |
.I pid |
| 33 |
is zero, then |
| 34 |
the parameters of the calling thread are set. |
| 35 |
The interpretation of |
| 36 |
the argument |
| 37 |
.I param |
| 38 |
depends on the scheduling policy |
| 39 |
of the thread identified by |
| 40 |
.IR pid . |
| 41 |
See |
| 42 |
.BR sched (7) |
| 43 |
for a description of the scheduling policies supported under Linux. |
| 44 |
.P |
| 45 |
.BR sched_getparam () |
| 46 |
retrieves the scheduling parameters for the |
| 47 |
thread identified by |
| 48 |
.IR pid . |
| 49 |
If |
| 50 |
.I pid |
| 51 |
is zero, then the parameters |
| 52 |
of the calling thread are retrieved. |
| 53 |
.P |
| 54 |
.BR sched_setparam () |
| 55 |
checks the validity of |
| 56 |
.I param |
| 57 |
for the scheduling policy of the thread. |
| 58 |
The value |
| 59 |
.I param\->sched_priority |
| 60 |
must lie within the |
| 61 |
range given by |
| 62 |
.BR sched_get_priority_min (2) |
| 63 |
and |
| 64 |
.BR sched_get_priority_max (2). |
| 65 |
.P |
| 66 |
For a discussion of the privileges and resource limits related to |
| 67 |
scheduling priority and policy, see |
| 68 |
.BR sched (7). |
| 69 |
.P |
| 70 |
POSIX systems on which |
| 71 |
.BR sched_setparam () |
| 72 |
and |
| 73 |
.BR sched_getparam () |
| 74 |
are available define |
| 75 |
.B _POSIX_PRIORITY_SCHEDULING |
| 76 |
in |
| 77 |
.IR <unistd.h> . |
| 78 |
.SH RETURN VALUE |
| 79 |
On success, |
| 80 |
.BR sched_setparam () |
| 81 |
and |
| 82 |
.BR sched_getparam () |
| 83 |
return 0. |
| 84 |
On error, \-1 is returned, and |
| 85 |
.I errno |
| 86 |
is set to indicate the error. |
| 87 |
.SH ERRORS |
| 88 |
.TP |
| 89 |
.B EINVAL |
| 90 |
Invalid arguments: |
| 91 |
.I param |
| 92 |
is NULL or |
| 93 |
.I pid |
| 94 |
is negative |
| 95 |
.TP |
| 96 |
.B EINVAL |
| 97 |
.RB ( sched_setparam ()) |
| 98 |
The argument |
| 99 |
.I param |
| 100 |
does not make sense for the current |
| 101 |
scheduling policy. |
| 102 |
.TP |
| 103 |
.B EPERM |
| 104 |
.RB ( sched_setparam ()) |
| 105 |
The caller does not have appropriate privileges |
| 106 |
(Linux: does not have the |
| 107 |
.B CAP_SYS_NICE |
| 108 |
capability). |
| 109 |
.TP |
| 110 |
.B ESRCH |
| 111 |
The thread whose ID is |
| 112 |
.I pid |
| 113 |
could not be found. |
| 114 |
.SH STANDARDS |
| 115 |
POSIX.1-2024. |
| 116 |
.SH HISTORY |
| 117 |
POSIX.1-2001. |
| 118 |
.SH SEE ALSO |
| 119 |
.ad l |
| 120 |
.nh |
| 121 |
.BR getpriority (2), |
| 122 |
.BR gettid (2), |
| 123 |
.BR nice (2), |
| 124 |
.BR sched_get_priority_max (2), |
| 125 |
.BR sched_get_priority_min (2), |
| 126 |
.BR sched_getaffinity (2), |
| 127 |
.BR sched_getscheduler (2), |
| 128 |
.BR sched_setaffinity (2), |
| 129 |
.BR sched_setattr (2), |
| 130 |
.BR sched_setscheduler (2), |
| 131 |
.BR setpriority (2), |
| 132 |
.BR capabilities (7), |
| 133 |
.BR sched (7) |