RTPRIO(2)
π rtprio(2) β the realtime / idle priority glow-up
okay bestie so you've found yourself in the System Calls Manual, section 2, and the star of the show is rtprio(2). It lives in the Standard C Library (libc, -lc) π«Ά
β¨ 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 πΈ
So here's the vibe: rtprio() looks up or changes the realtime or idle priority of a process, or of the calling thread. And rtprio_thread() does the same little lookup/change dance but for a thread specifically. Iconic division of labor, no cap. π
The function argument β what are we even doing here
The function argument specifies the operation to be performed:
RTP_LOOKUPβ to lookup the current priority πRTP_SETβ to set the priority π οΈ
The pid argument (for rtprio())
For the rtprio() system call, the pid argument specifies the process to operate on, and 0 means π 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, all depending on the value of the function argument. It's giving "main character of the whole process" energy, honestly.
The lwpid argument (for rtprio_thread())
For the rtprio_thread() system call, the lwpid specifies the thread to operate on, and 0 means π the calling thread.
The *rtp argument β the struct moment
The *rtp argument is a pointer to a struct rtprio, which is what you use to specify the priority and the priority type. And this little guy 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 πΏRTP_PRIO_IDLEβ for idle priorities π΄
The priority specified by the prio field ranges between 0 and RTP_PRIO_MAX (usually 31). And heads up: 0 is the highest possible priority. Yes, backwards from what your brain wants, we know, it's a whole thing. π
Inheritance tea β
Realtime and idle priority is inherited through fork() and exec(). It's literally in the bloodline. π§¬
Scheduling behavior, AKA who preempts whom
- 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 β slay β¨. 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]β Thertppointer passed tortprio()orrtprio_thread()was invalid. π[EINVAL]β The specifiedpriowas 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 themac_priority(4)policy and therealtimeandidletimeuser groups. Thesysctl(8)variablesecurity.bsd.unprivileged_idpriois 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), ps(1), rtprio(1), setpriority(2), nice(3), mac_priority(4), renice(8), p_cansee(9)
π AUTHORS π
The original author was Henrik Vestergaard Draboel <hvd@terry.ping.dk> π. This implementation in FreeBSD was substantially rewritten by David Greenman. And the rtprio_thread() system call was implemented by David Xu. Legends, all of them, fr fr. π«Ά
okay that's the whole page bestie, go forth and prioritize responsibly π β¨
Source: Debian Β· December 8, 2021 Β· RTPRIO(2) β mwah, that's the sign-off, ily, bye π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1994, Henrik Vestergaard Draboel
- Copyright (c) 2011 Xin LI <delphij@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms