PTHREAD_SCHEDPARAM(3)
π PTHREAD_SCHEDPARAM(3) β thread scheduling parameter manipulation, bestie edition
okay so this is a page from the Library Functions Manual and honestly? it's giving "let me control exactly how your thread gets its turn on the CPU." We're talking pthread_setschedparam and pthread_getschedparam β the setter and the getter. iconic duo, no cap π
π LIBRARY
POSIX Threads Library β that's libpthread, and you link it with -lpthread. periodt.
β¨ SYNOPSIS β¨
#include <pthread.h>
int
pthread_setschedparam(pthread_t thread, int policy,
const struct sched_param *param);
int
pthread_getschedparam(pthread_t thread, int *restrict policy,
struct sched_param *restrict param);
π¦ DESCRIPTION π¦
So pthread_setschedparam() and pthread_getschedparam() set and get the scheduling parameters of individual threads. Like, per-thread vibes. Not the whole process, bestie β one thread at a time π
The scheduling policy for a thread can be one of these three:
SCHED_FIFOβ first in, first out πSCHED_RRβ round-robin πSCHED_OTHERβ timesharing β
And the valid thread priorities β those you access via param->sched_priority β have to be within the range returned by the sched_get_priority_min(2) and sched_get_priority_max(2) system calls. That's the range, okay? don't go outside it π
π«Ά RETURN VALUES π«Ά
If everything's slaying, these functions return 0. Otherwise an error number comes back to tell you what went wrong. that's it, that's the whole thing.
π ERRORS π
So pthread_setschedparam() will fail if:
[EINVAL]β invalid value for policy. (you gave it a policy that isn't a policy, bestie π)[ENOTSUP]β invalid value for scheduling parameters.[EPERM]β the calling thread does not have sufficient privilege to perform the operation. (no permission, no party π₯)[ESRCH]β non-existent thread thread.
And pthread_getschedparam() will fail if:
[ESRCH]β non-existent thread thread. (same energy, thread literally not found)
π SEE ALSO π
πΈ STANDARDS πΈ
The pthread_setschedparam() and pthread_getschedparam() functions conform to Version 2 of the Single UNIX Specification (βSUSv2β). certified official, iykyk β¨
ngl the whole thing is a two-function page and it still ate. read the min/max priority calls before you go setting anything, fr fr π§
mwah π this page came from Debian, dated October 17, 2022 β and that's the whole manual page, bestie, see you in the next one π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms