sched_setscheduler, sched_getscheduler − set and get scheduling policy/parameters


#include <sched.h>

int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *

int sched_getscheduler(pid_t pid);


The sched_setscheduler() system call sets both the scheduling policy and parameters for the thread whose ID is specified in pid. If pid equals zero, the scheduling policy and parameters of the calling thread will be set.

The scheduling parameters are specified in the param argument, which is a pointer to a structure of the following form:

struct sched_param {
int sched_priority;

In the current implementation, the structure contains only one field, sched_priority. The interpretation of param depends on the selected policy.

Currently, Linux supports the following "normal" (i.e., non-real-time) scheduling policies as values that may be specified in policy:


the standard round-robin time-sharing policy;


for "batch" style execution of processes; and


for running very low priority background jobs.

For each of the above policies, param−>sched_priority must be 0.

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:


a first-in, first-out policy; and


a round-robin policy.

For each of the above policies, param−>sched_priority specifies a scheduling priority for the thread. This is a number in the range returned by calling sched_get_priority_min(2) and sched_get_priority_min(2) with the specified policy. On Linux, these system calls return, respectively, 1 and 99.

Since Linux 2.6.32, the SCHED_RESET_ON_FORK flag can be ORed in policy when calling sched_setscheduler(). As a result of including this flag, children created by fork(2) do not inherit privileged scheduling policies. See sched(7) for details.

sched_getscheduler() returns the current scheduling policy of the thread identified by pid. If pid equals zero, the policy of the calling thread will be retrieved.


On success, sched_setscheduler() returns zero. On success, sched_getscheduler() returns the policy for the thread (a nonnegative integer). On error, both calls return −1, and errno is set appropriately.



Invalid arguments: pid is negative or param is NULL.


(sched_setscheduler()) policy is not one of the recognized policies.


(sched_setscheduler()) param does not make sense for the specified policy.


The calling thread does not have appropriate privileges.


The thread whose ID is pid could not be found.


POSIX.1-2001 (but see BUGS below). The SCHED_BATCH and SCHED_IDLE policies are Linux-specific.


Further details of the semantics of all of the above "normal" and "real-time" scheduling policies can be found in sched(7).

POSIX systems on which sched_setscheduler() and sched_getscheduler() are available define _POSIX_PRIORITY_SCHEDULING in <unistd.h>.

POSIX.1 does not detail the permissions that an unprivileged thread requires in order to call sched_setscheduler(), and details vary across systems. For example, the Solaris 7 manual page says that the real or effective user ID of the caller must match the real user ID or the save set-user-ID of the target.

The scheduling policy and parameters are in fact per-thread attributes on Linux. The value returned from a call to gettid(2) can be passed in the argument pid. Specifying pid as 0 will operate on the attributes of the calling thread, and passing the value returned from a call to getpid(2) will operate on the attributes of the main thread of the thread group. (If you are using the POSIX threads API, then use pthread_setschedparam(3), pthread_getschedparam(3), and pthread_setschedprio(3), instead of the sched_*(2) system calls.)


POSIX says that on success, sched_setscheduler() should return the previous scheduling policy. Linux sched_setscheduler() does not conform to this requirement, since it always returns 0 on success.


nice(2), sched_get_priority_max(2), sched_get_priority_min(2), sched_getaffinity(2), sched_getattr(2), sched_getparam(2), sched_rr_get_interval(2), sched_setaffinity(2), sched_setattr(2), sched_setparam(2), sched_yield(2), setpriority(2), capabilities(7), cpuset(7), sched(7)


This page is part of release 3.69 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−pages/.

More Linux Commands

XRecolorCursor(3) - manipulate cursors - Linux manual page
The XRecolorCursor function changes the color of the specified cursor, and if the cursor is being displayed on a screen, the change is visible immediately. The

vfs_cap(8) - CAP encode filenames - Linux manual page.......
This VFS module is part of the samba(7) suite. CAP (Columbia Appletalk Protocol) encoding is a technique for representing non-ASCII filenames in ASCII. The vfs_

glDrawRangeElements(3gl) - render primitives from array data
glDrawRangeElements is a restricted form of glDrawElements. mode, start, end, and count match the corresponding arguments to glDrawElements, with the additional

glPixelZoom(3gl) - specify the pixel zoom factors (ManPage)
glPixelZoom specifies values for the $x$ and $y$ zoom factors. During the execution of glDrawPixels or glCopyPixels, if ($xr $, $yr $) is the current raster pos

ntfs-3g.probe(8) - Probe an NTFS volume mountability........
The ntfs-3g.probe utility tests a volume if its NTFS mountable read-only or read-write, and exits with a status value accordingly. The volume can be a block dev

clnt_perror(3) - library routines for remote procedure calls
These routines allow C programs to make procedure calls on other machines across the network. First, the client calls a procedure to send a data packet to the s

enscript(1) - convert text files to PostScript, HTML, RTF, A
Enscript converts text files to PostScript or to other output languages. Enscript can spool the generated output directly to a specified printer or leave it to

libtool(1) - manual page for libtool 2.4 - Linux man page...
Provide generalized library-building support services. --config show all configuration variables --debug enable verbose shell tracing -n, --dry-run display comm

glutSolidDodecahedron(3) - render a solid or wireframe dodec
glutSolidDodecahedron and glutWireDodecahedron render a solid or wireframe dodecahedron respectively centered at the modeling coordinates origin with a radius o

gnutls_x509_crq_get_extension_info(3) - API function........
gnutls_x509_crq_get_extension_info.3 - This function will return the requested extension OID in the certificate, and the critical flag for it. The extension OID

ldap_start_tls(3) - LDAP TLS initialization routines........
These routines are used to initiate TLS processing on an LDAP session. ldap_start_tls_s() sends a StartTLS request to a server, waits for the reply, and then in

btrfs-debug-tree(8) dump btrfs filesystem metadata into stdo
btrfs-debug-tree is used to dump the whole tree of the given device. This is maybe useful for analyzing filesystem state or inconsistence and has a positive edu

We can't live, work or learn in freedom unless the software we use is free.