---
name: "sched_getscheduler"
section: "2"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/sched_setscheduler"
---

# sched\_getscheduler(2)

set and get scheduling policy/parameters

Part of [sched\_setscheduler(2)](/sched_setscheduler/2.md).

## NAME

sched\_setscheduler, sched\_getscheduler - set and get scheduling policy/parameters

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <sched.h>
```

**int sched\_setscheduler(pid\_t** *pid***, int** *policy***,**                        **const struct sched\_param \****param***);** **int sched\_getscheduler(pid\_t** *pid***);**

## DESCRIPTION

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*:

- **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.

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)](/sched/7.md). 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.

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)](/sched_get_priority_min/2.md) and [**sched\_get\_priority\_max**(2)](/sched_get_priority_max/2.md) 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)](/fork/2.md) do not inherit privileged scheduling policies. See [**sched**(7)](/sched/7.md) 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.

## RETURN VALUE

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 to indicate the error.

## ERRORS

- **EINVAL**

  Invalid arguments: *pid* is negative or *param* is NULL.

- **EINVAL**

  (**sched\_setscheduler**()) *policy* is not one of the recognized policies.

- **EINVAL**

  (**sched\_setscheduler**()) *param* does not make sense for the specified *policy*.

- **EPERM**

  The calling thread does not have appropriate privileges.

- **ESRCH**

  The thread whose ID is *pid* could not be found.

## VERSIONS

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)](/gettid/2.md) 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)](/getpid/2.md) 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_setschedparam/3.md), [**pthread\_getschedparam**(3)](/pthread_getschedparam/3.md), and [**pthread\_setschedprio**(3)](/pthread_setschedprio/3.md), instead of the **sched\_\***(2) system calls.)

## STANDARDS

POSIX.1-2024 (but see BUGS below).

**SCHED\_BATCH** and **SCHED\_IDLE** are Linux-specific.

## HISTORY

POSIX.1-2001.

## NOTES

Further details of the semantics of all of the above "normal" and "real-time" scheduling policies can be found in the [**sched**(7)](/sched/7.md) manual page. That page also describes an additional policy, **SCHED\_DEADLINE**, which is settable only via [**sched\_setattr**(2)](/sched_setattr/2.md).

POSIX systems on which **sched\_setscheduler**() and **sched\_getscheduler**() are available define **\_POSIX\_PRIORITY\_SCHEDULING** in *\<unistd.h\>*.

## BUGS

POSIX.1 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.

## SEE ALSO

[**chrt**(1)](/chrt/1.md), [**nice**(2)](/nice/2.md), [**sched\_get\_priority\_max**(2)](/sched_get_priority_max/2.md), [**sched\_get\_priority\_min**(2)](/sched_get_priority_min/2.md), [**sched\_getaffinity**(2)](/sched_getaffinity/2.md), [**sched\_getattr**(2)](/sched_getattr/2.md), [**sched\_getparam**(2)](/sched_getparam/2.md), [**sched\_rr\_get\_interval**(2)](/sched_rr_get_interval/2.md), [**sched\_setaffinity**(2)](/sched_setaffinity/2.md), [**sched\_setattr**(2)](/sched_setattr/2.md), [**sched\_setparam**(2)](/sched_setparam/2.md), [**sched\_yield**(2)](/sched_yield/2.md), [**setpriority**(2)](/setpriority/2.md), [**capabilities**(7)](/capabilities/7.md), [**cpuset**(7)](/cpuset/7.md), [**sched**(7)](/sched/7.md)
