getpriority(2)
๐ getpriority(2) โ the manual, but make it make sense ๐
okay bestie, sit down, hydrate, because we're about to learn how to get and set program scheduling priority and honestly? it's giving "I control the vibes of the whole scheduler". it's getpriority and setpriority, from the System Calls Manual, and I'm gonna hold your hand through every single line. no cap. ๐ซถ
โจ NAME โจ
getpriority, setpriority โ get/set program scheduling priority. that's it, that's the whole job, and they do it flawlessly. ๐
๐ LIBRARY ๐
Standard C library โ the one and only libc, and you link it with -lc. she's always there for you. ๐
๐ SYNOPSIS ๐
#include <sys/resource.h>
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int prio);
look at those signatures. so clean. so crisp. main character energy fr. โจ
๐ธ DESCRIPTION ๐ธ
So here's the tea, bestie: the scheduling priority of a process, a process group, or a user โ whichever one you point at with which and who โ gets obtained with the getpriority() call and set with the setpriority() call. and the process attribute these syscalls are messing with is literally the same attribute the whole time (aka the "nice" value) that nice(2) deals with. same vibe, different door. ๐ช
The which argument is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and who gets interpreted relative to which โ like, it means a process identifier when which is PRIO_PROCESS, a process group identifier when it's PRIO_PGRP, and a user ID when it's PRIO_USER. and if you hand it a who of zero? it denotes, respectively, the calling process, the process group of the calling process, or the real user ID of the calling process. zero = "me, myself, and I" energy. ๐
Now, the prio argument is a value in the range -20 to 19 (but pls see NOTES below, I'm not done with you yet), where -20 is the highest priority and 19 is the lowest priority. and if you try to set a priority outside that range? it gets silently clamped to the range. no error, no drama, just quietly corrected like a friend fixing your eyeliner. ๐
The default priority is 0, and lower values give a process a higher scheduling priority. yes, it's backwards, yes, we've all accepted this, it's iconic in a cursed way. ๐
getpriority() returns the highest priority โ that's the lowest numerical value โ enjoyed by any of the specified processes. setpriority() sets the priorities of all of the specified processes to the specified value. periodt.
Traditionally, only a privileged process could lower the nice value (i.e., set a higher priority). However, since Linux 2.6.12, an unprivileged process can decrease the nice value of a target process that has a suitable RLIMIT_NICE soft limit โ go read getrlimit(2) for the details, bestie. glow-up of the century tbh. โจ
๐ฆ RETURN VALUE ๐ฆ
On success, getpriority() returns the calling thread's nice value, which may be a negative number. on error, it returns -1 and sets errno to indicate the error.
โ ๏ธ okay this part is IMPORTANT, don't skip it: since a successful call togetpriority()can legitimately return the value -1, you have to clearerrnoprior to the call, then checkerrnoafterward to figure out whether that-1is an error or a legit value. it's giving "gaslight, gatekeep, girlboss" but for errno. ๐ญ
setpriority() returns 0 on success. on failure, it returns -1 and sets errno to indicate the error. simple. flawless. no notes. ๐
๐ ERRORS ๐
EACCESโ the caller attempted to set a lower nice value (i.e., a higher process priority) but did not have the required privilege. on Linux: did not have theCAP_SYS_NICEcapability. the audacity? denied. ๐EINVALโwhichwas not one ofPRIO_PROCESS,PRIO_PGRP, orPRIO_USER. you gave it a stranger and it said no. ๐EPERMโ a process was located, but its effective user ID did not match either the effective or the real user ID of the caller, and it was not privileged (on Linux: did not have theCAP_SYS_NICEcapability). but see HISTORY below. ๐ESRCHโ no process was located using thewhichandwhovalues you specified. ghosted. literally nobody home. ๐ป
๐ STANDARDS ๐
POSIX.1-2024. certified, stamped, respected. ๐
๐ง HISTORY ๐ง
4.2BSD, SVr4, SUSv1, POSIX.1-2001 XSI. a whole lineage, a whole dynasty. ๐ซถ
okay so the details on the condition for EPERM depend on the system. the description above is what POSIX.1-2001 says, and it seems to be followed on all System V-like systems. Linux kernels before Linux 2.6.12 required the real or effective user ID of the caller to match the real user of the process who โ (instead of its effective user ID, bestie, read that again). Linux 2.6.12 and later require the effective user ID of the caller to match the real or effective user ID of the process who. and all BSD-like systems (SunOS 4.1.3, Ultrix 4.2, 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same manner as Linux 2.6.12 and later. so basically everyone agreed except old Linux. ancient beef. ๐ต
๐ NOTES ๐
for further details on the nice value, go see sched(7). it's the extended universe. ๐
Note: the addition of the"autogroup"feature in Linux 2.6.38 means that the nice value no longer has its traditional effect in many circumstances. for details, seesched(7). yes, this is real, yes, it changed everything, no, I'm not okay about it. ๐ญ
a child created by fork(2) inherits its parent's nice value. and the nice value is preserved across execve(2). she survives the transformation. that's called resilience. โจ
๐ C library/kernel differences ๐
The getpriority system call returns nice values translated to the range 40..1, because a negative return value would be interpreted as an error โ sneaky little workaround, we love a hack. ๐
The glibc wrapper function for getpriority() translates the value back according to the formula:
unice = 20 - knice
so the 40..1 range returned by the kernel corresponds to the range -20..19 as seen by user space. math? ate. ๐ฝ๏ธ
๐ BUGS ๐
According to POSIX, the nice value is a per-process setting. However, under the current Linux/NPTL implementation of POSIX threads, the nice value is a per-thread attribute โ meaning different threads in the same process can have different nice values. ๐ณ
Portable applications should avoid relying on the Linux behavior, which may be made standards conformant in the future. so likeโฆ don't build your whole personality on it, bestie. ๐
๐ SEE ALSO ๐
and also: Documentation/scheduler/sched-nice-design.rst in the Linux kernel source tree (since Linux 2.6.23). deep lore for the scholars. ๐
and that's the whole page, bestie!! go forth and set your priorities (maybe not to -20, you're not that privileged, EACCES said no ๐
). this was the getpriority(2) manual page from Linux man-pages 6.20, dated 2026-01-23 โ that's the source, that's the version, that's the date, and that's the sign-off. mwah. ๐๐โจ๐ฆ๐ธ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: BSD-4-Clause-UC
- Copyright 1980-1991, The Regents of the University of California
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms