RTPRIO(2)
π RTPRIO(2) β the manual page, but make it cute π
okay so bestie, welcome to rtprio, rtprio_thread β literally the syscalls that let you examine or modify realtime or idle priority. Yes. We're playing with scheduling vibes today. Sit down, hydrate, and let's get into it. π«Ά
π LIBRARY
Standard C Library (libc, -lc) β the classic. She's always there for you. π
β¨ 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);
Look at those signatures. Gorgeous. Iconic. No notes. π
π¦ DESCRIPTION π¦
So, the rtprio() system call is used to lookup or change the realtime or idle priority of a process β or of the calling thread, if you're feeling low-key about it. And rtprio_thread() is used to lookup or change the realtime or idle priority of a thread. That's the whole assignment. She's focused. π
The function argument is the "what are we even doing here" knob, and it specifies the operation to be performed:
RTP_LOOKUPβ bestie, we're just looking. π Lookup the current priority.RTP_SETβ we're changing it. Setting the priority. Main character move. β¨
For the rtprio() system call, the pid argument specifies the process to operate on β and 0 means the calling thread. (Yeah, she said process but then said 0 for thread. It's giving flexible. πΈ) 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 the value of the function argument. So it's either a gossip report or a full group-chat announcement, no in-between. π
For the rtprio_thread() system call, the lwpid specifies the thread to operate on, and 0 means the calling thread. Same energy, smaller target. π
The *rtp argument is a pointer to a struct rtprio, which is used to specify the priority and priority type. And this structure β I'm obsessed β has the following form:
struct rtprio {
u_short type;
u_short prio;
};
Two little fields. Tiny. Powerful. The way that two u_shorts are carrying the entire scheduling destiny of a thread?? π
The value of the type field may be:
RTP_PRIO_REALTIMEβ for realtime priorities. She's urgent. She's now. π₯RTP_PRIO_NORMALβ for normal priorities. Just a girl. πRTP_PRIO_IDLEβ for idle priorities. Only when nothing else is happening. Respectfully. π
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. Number go up, priority go down. That's just the lore. π€·βοΈ
Realtime and idle priority is inherited through fork() and exec(). So it runs in the family. Generational priority, fr fr. π§¬
Okay and now the actual behavior, which is the juicy part:
- A realtime thread can only be preempted by a thread of equal or higher priority, or by an interrupt. Nothing else can touch her. π
- Idle priority threads will run only when no other real/normal priority thread is runnable. They're the "text me when you're free" friend. π₯Ί
- Higher real/idle priority threads preempt lower real/idle priority threads. Ranking matters. β
- Threads of equal real/idle priority are run round-robin. Everybody gets a turn, we take turns in this house. π«Ά
π 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. So 0 = slay, -1 = check errno, bestie. π
π¨ ERRORS π¨
The rtprio() and rtprio_thread() system calls will fail if:
[EFAULT]β Thertppointer passed tortprio()orrtprio_thread()was invalid. Bad pointer, babe. She's not there. π[EINVAL]β The specifiedpriowas out of range. You colored outside the lines. π[EPERM]β The calling thread is not allowed to set the realtime priority. Listen: only root is allowed to change the realtime priority of any thread, and non-root may only change the idle priority of threads the user owns, when thesysctl(8)variablesecurity.bsd.unprivileged_idpriois set to non-zero. So like, permissions are real. Do not test her. π«[ESRCH]β The specified process or thread was not found or visible. She's not in the group chat. Can't find her. π
π SEE ALSO π
nice(1), ps(1), rtprio(1), setpriority(2), nice(3), renice(8), p_cansee(9)
Go read those too, bestie. Cross-referencing is self-care. πβ¨
π«Ά 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. Legends, all of them. Thank you for your service. π
And that's the page!! This one's from the Debian crew, dated December 27, 2011 β oldie but a goodie, and she still ate. π β¨ Now go set some priorities (responsibly, as root, obviously). Byeee π¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1994, Henrik Vestergaard Draboel
- Copyright (c) 2011 Xin LI <delphij@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms