sched_getattr (2) - Linux Manuals
NAME
sched_setattr, sched_getattr - set and get scheduling policy and attributes
SYNOPSIS
#include <sched.h> int sched_setattr(pid_t pid, struct sched_attr *attr, unsigned int flags); int sched_getattr(pid_t pid, struct sched_attr *attr, unsigned int size, unsigned int flags);
DESCRIPTION
sched_setattr()
The sched_setattr() system call sets the scheduling policy and associated attributes for the thread whose ID is specified in pid. If pid equals zero, the scheduling policy and attributes of the calling thread will be set.Currently, Linux supports the following "normal" (i.e., non-real-time) scheduling policies as values that may be specified in policy:
- SCHED_OTHER
- the standard round-robin time-sharing policy;
- SCHED_BATCH
- for "batch" style execution of processes; and
- SCHED_IDLE
- for running very low priority background jobs.
Various "real-time" policies are also supported, for special time-critical applications that need precise control over the way in which runnable threads are selected for execution. For the rules governing when a process may use these policies, see sched(7). The real-time policies that may be specified in policy are:
- SCHED_FIFO
- a first-in, first-out policy; and
- SCHED_RR
- a round-robin policy.
Linux also provides the following policy:
- SCHED_DEADLINE
- a deadline scheduling policy; see sched(7) for details.
The attr argument is a pointer to a structure that defines the new scheduling policy and attributes for the specified thread. This structure has the following form:
struct sched_attr {
The fields of the
sched_attr
structure are as follows:
The
flags
argument is provided to allow for future extensions to the interface;
in the current implementation it must be specified as 0.
The
size
argument should be set to the size of the
sched_attr
structure as known to user space.
The value must be at least as large as the size of the initially published
sched_attr
structure, or the call fails with the error
EINVAL.
The retrieved scheduling attributes are placed in the fields of the
sched_attr
structure pointed to by
attr.
The kernel sets
attr.size
to the size of its
sched_attr
structure.
If the caller-provided
attr
buffer is larger than the kernel's
sched_attr
structure,
the additional bytes in the user-space structure are not touched.
If the caller-provided structure is smaller than the kernel
sched_attr
structure, the kernel will silently not return any values which would be stored
outside the provided space.
As with
sched_setattr(),
these semantics allow for future extensibility of the interface.
The
flags
argument is provided to allow for future extensions to the interface;
in the current implementation it must be specified as 0.
In addition,
sched_getattr()
can fail for the following reasons:
In addition,
sched_setattr()
can fail for the following reasons:
In Linux versions up to 5.3,
sched_getattr()
failed with the error
EFBIG
if the in-kernel
sched_attr
structure was larger than the
size
passed by user space.
sched_getattr()
The
sched_getattr()
system call fetches the scheduling policy and the
associated attributes for the thread whose ID is specified in
pid.
If
pid
equals zero,
the scheduling policy and attributes of the calling thread
will be retrieved.
RETURN VALUE
On success,
sched_setattr()
and
sched_getattr()
return 0.
On error, -1 is returned, and
errno
is set to indicate the cause of the error.
ERRORS
sched_getattr()
and
sched_setattr()
can both fail for the following reasons:
VERSIONS
These system calls first appeared in Linux 3.14.
CONFORMING TO
These system calls are nonstandard Linux extensions.
NOTES
sched_setattr()
provides a superset of the functionality of
sched_setscheduler(2),
sched_setparam(2),
nice(2),
and (other than the ability to set the priority of all processes
belonging to a specified user or all processes in a specified group)
setpriority(2).
Analogously,
sched_getattr()
provides a superset of the functionality of
sched_getscheduler(2),
sched_getparam(2),
and (partially)
getpriority(2).
BUGS
In Linux versions up to
3.15,
sched_setattr()
failed with the error
EFAULT
instead of
E2BIG
for the case described in ERRORS.
COLOPHON
This page is part of release 5.10 of the Linux
man-pages
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
https://www.kernel.org/doc/man-pages/.
SEE ALSO
chrt(1),
nice(2),
sched_get_priority_max(2),
sched_get_priority_min(2),
sched_getaffinity(2),
sched_getparam(2),
sched_getscheduler(2),
sched_rr_get_interval(2),
sched_setaffinity(2),
sched_setparam(2),
sched_setscheduler(2),
sched_yield(2),
setpriority(2),
pthread_getschedparam(3),
pthread_setschedparam(3),
pthread_setschedprio(3),
capabilities(7),
cpuset(7),
sched(7)