sched_setparam(2)
๐ sched_setparam(2) โ System Calls Manual, bestie edition ๐
okay so like. this is a page from the System Calls Manual, and it's all about two little syscalls that let you peek and poke at how your threads get scheduled. very main character of them honestly. let's get into it ๐ธ
โจ NAME โจ
sched_setparam, sched_getparam โ set and get scheduling parameters ๐
๐ LIBRARY ๐
Standard C library (libc, -lc) โ yeah bestie, you just link the normal libc, no extra drama ๐ซถ
๐ฆ SYNOPSIS ๐ฆ
#include <sched.h>
int sched_setparam(pid_t pid, const struct sched_param *param);
int sched_getparam(pid_t pid, struct sched_param *param);
struct sched_param {
...
int sched_priority;
...
};
like. look at that struct. it's giving "there's more in here but we only care about sched_priority for now" ๐ญ iconic honestly.
๐ DESCRIPTION ๐
<purple>sched_setparam()</purple> sets the scheduling parameters that go with the scheduling policy for the thread whose thread ID you pass in pid. if pid is zero, then you're setting the parameters of the calling thread itself โ yes, you can just vibe and adjust your own self, no cap โจ
the way that param gets interpreted? that depends entirely on the scheduling policy of the thread that pid points at. for the full rundown of what scheduling policies Linux supports, go read sched(7). slay.
<purple>sched_getparam()</purple> is the other half of the duo โ it retrieves the scheduling parameters for the thread identified by pid. and yeah, if pid is zero, you get the parameters of the calling thread back. symmetry!! ๐ฆ
now here's the important bit: sched_setparam() checks the validity of param against the scheduling policy of the thread. and param->sched_priority must lie inside the range you get from sched_get_priority_min(2) and sched_get_priority_max(2). outside that range? nope. not happening. ๐
for the whole discussion of privileges and resource limits that come with scheduling priority and policy, again: sched(7). it's the lore. ๐
also, POSIX systems where sched_setparam() and sched_getparam() actually exist will define _POSIX_PRIORITY_SCHEDULING in <unistd.h>. so if you're checking portability, that's your little signal flag ๐
๐ RETURN VALUE ๐
on success, both sched_setparam() and sched_getparam() return 0. periodt. โจ
on error, -1 is returned, and errno gets set to tell you what went wrong. (rude of it, but okay, we move.) ๐ญ
๐ ERRORS ๐
EINVALโ invalid arguments, bestie:paramisNULLorpidis negative. we don't do that here ๐EINVALโ (sched_setparam()only) the argumentparamjust does not make sense for the current scheduling policy. it's giving mismatch, it's giving not compatible ๐EPERMโ (sched_setparam()only) the caller does not have the appropriate privileges. on Linux specifically: it does not have theCAP_SYS_NICEcapability. so like, you tried and the kernel said no ๐ESRCHโ the thread whose ID ispidcould not be found. gone. missing. not in this building ๐
โญ STANDARDS โญ
POSIX.1-2024. the fresh one. slay ๐
๐ธ HISTORY ๐ธ
POSIX.1-2001. so it's been around a minute, and it's still iconic ๐ซถ
๐ฅ SEE ALSO ๐ฅ
getpriority(2), gettid(2), nice(2), sched_get_priority_max(2), sched_get_priority_min(2), sched_getaffinity(2), sched_getscheduler(2), sched_setaffinity(2), sched_setattr(2), sched_setscheduler(2), setpriority(2), capabilities(7), sched(7)
and that's the whole page, bestie! go forth and schedule responsibly ๐
this page came from Linux man-pages 6.20, dated 2026-02-08, and it's literally called sched_setparam(2) โ ily, 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: GPL-2.0-or-later
- Copyright 1996, Tom Bjorkholm <tomb@mydata.se>
- Copyright 1996, Markus Kuhn <mkuhn@acm.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms