---
name: "rtprio"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/rtprio/2"
---

# rtprio(2)

examine or modify realtime or idle priority

## NAME

**rtprio**, **rtprio\_thread** – examine or modify realtime or idle priority

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<sys/rtprio.h\>**

*int*\

**rtprio**(*int function*, *pid\_t pid*, *struct rtprio \*rtp*);

*int*\

**rtprio\_thread**(*int function*, *lwpid\_t lwpid*, *struct rtprio \*rtp*);

## DESCRIPTION

The **rtprio**() system call is used to lookup or change the realtime or idle priority of a process, or the calling thread. The **rtprio\_thread**() system call is used to lookup or change the realtime or idle priority of a thread.

The *function* argument specifies the operation to be performed. RTP\_LOOKUP to lookup the current priority, and RTP\_SET to set the priority.

For the **rtprio**() system call, the *pid* argument specifies the process to operate on, 0 for the calling thread. When *pid* is non-zero, the system call reports the highest priority in the process, or sets all threads' priority in the process, depending on value of the *function* argument.

For the **rtprio\_thread**() system call, the *lwpid* specifies the thread to operate on, 0 for the calling thread.

The *\*rtp* argument is a pointer to a struct rtprio which is used to specify the priority and priority type. This structure has the following form:

```
struct rtprio {
	u_short	type;
	u_short prio;
};
```

The value of the *type* field may be RTP\_PRIO\_REALTIME for realtime priorities, RTP\_PRIO\_NORMAL for normal priorities, and RTP\_PRIO\_IDLE for idle priorities. The priority specified by the *prio* field ranges between 0 and RTP\_PRIO\_MAX (usually 31). 0 is the highest possible priority.

Realtime and idle priority is inherited through **fork**() and **exec**().

A realtime thread can only be preempted by a thread of equal or higher priority, or by an interrupt; idle priority threads will run only when no other real/normal priority thread is runnable. Higher real/idle priority threads preempt lower real/idle priority threads. Threads of equal real/idle priority are run round-robin.

## RETURN VALUES

The **rtprio()** and **rtprio\_thread()** functions return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

The **rtprio**() and **rtprio\_thread**() system calls will fail if:

- \[EFAULT\]

  The rtp pointer passed to **rtprio**() or **rtprio\_thread**() was invalid.

- \[EINVAL\]

  The specified *prio* was out of range.

- \[EPERM\]

  The calling thread is not allowed to set the priority. Only root is allowed to change the realtime or idle priority of any thread. Exceptional privileges can be granted through the [mac\_priority(4)](/mac_priority/4.md) policy and the realtime and idletime user groups. The [sysctl(8)](/sysctl/8.md) variable *security.bsd.unprivileged\_idprio* is deprecated. If set to non-zero, it lets any user change the idle priority of threads they own.

- \[ESRCH\]

  The specified process or thread was not found or visible.

## SEE ALSO

[nice(1)](/nice/1.md), [ps(1)](/ps/1.md), [rtprio(1)](/rtprio/1.md), [setpriority(2)](/setpriority/2.md), [nice(3)](/nice/3.md), [mac\_priority(4)](/mac_priority/4.md), [renice(8)](/renice/8.md), [p\_cansee(9)](/p_cansee/9.md)

## AUTHORS

The original author was Henrik Vestergaard Draboel ⟨*hvd@terry.ping.dk*⟩. This implementation in FreeBSD was substantially rewritten by David Greenman. The **rtprio\_thread**() system call was implemented by David Xu.
