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: param is NULL or pid is negative. we don't do that here ๐Ÿ™ˆ
  • EINVAL โ€” (sched_setparam() only) the argument param just 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 the CAP_SYS_NICE capability. so like, you tried and the kernel said no ๐Ÿ’€
  • ESRCH โ€” the thread whose ID is pid could 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms