SCHED_SETSCHEDULER(3POSIX)
๐ธ SCHED_SETSCHEDULER(3POSIX) ๐ธ
okay bestie, welcome to the POSIX Programmer's Manual, page SCHED_SETSCHEDULER(3POSIX). sit down, hydrate, and let's talk about telling the kernel how to schedule stuff ๐
โจ PROLOG โจ
so like, real talk first: this page is part of the POSIX Programmer's Manual. the Linux implementation of this interface might be different from what's written here (if you're on Linux, go check the corresponding Linux manual page for the actual tea โ), or honestly the interface might not even be implemented on Linux at all. no cap.
๐ NAME ๐
sched_setscheduler โ set scheduling policy and parameters (REALTIME)
it's giving REALTIME energy fr fr ๐ฅ
๐ฆ SYNOPSIS ๐ฆ
#include <sched.h>
int sched_setscheduler(pid_t pid, int policy,
const struct sched_param *param);
๐ DESCRIPTION ๐
okay so here's the whole vibe. the sched_setscheduler() function shall set the scheduling policy and scheduling parameters of the process specified by pid to policy and the parameters specified in the sched_param structure pointed to by param, respectively. (yes, "respectively", she's fancy like that โจ)
the value of the sched_priority member in the sched_param structure shall be any integer within the inclusive priority range for the scheduling policy specified by policy. and um, if the value of pid is negative? the behavior of the sched_setscheduler() function is unspecified. so like... don't. ๐
the possible values for the policy parameter are defined in the <sched.h> header. iconic header, honestly.
if a process specified by pid exists, and if the calling process has permission, the scheduling policy and scheduling parameters shall be set for the process whose process ID is equal to pid.
if pid is zero, the scheduling policy and scheduling parameters shall be set for the calling process. (it's you. you're the main character. ๐)
the conditions under which one process has appropriate privileges to change the scheduling parameters of another process are implementation-defined. iykyk.
implementations may require that the requesting process have permission to set its own scheduling parameters or those of another process. additionally, implementation-defined restrictions may apply as to the appropriate privileges required to set the scheduling policy of the process, or the scheduling policy of another process, to a particular value. so many rules bestie, but they're all in here, promise ๐ซถ
the sched_setscheduler() function shall be considered successful if it succeeds in setting the scheduling policy and scheduling parameters of the process specified by pid to the values specified by policy and the structure pointed to by param, respectively. slay.
see Scheduling Policies for a description on how this function affects the scheduling of the threads within the target process.
if the current scheduling policy for the target process is not SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC, the result is implementation-defined; this case includes the SCHED_OTHER policy. (yes, SCHED_OTHER counts. i know. wild.)
the specified sched_ss_repl_period shall be greater than or equal to the specified sched_ss_init_budget for the function to succeed; if it is not, then the function shall fail. ๐
the value of sched_ss_max_repl shall be within the inclusive range [1,{SS_REPL_MAX}] for the function to succeed; if not, the function shall fail. and ngl, it is unspecified whether the sched_ss_repl_period and sched_ss_init_budget values are stored as provided by this function or are rounded to align with the resolution of the clock being used. mystery behavior, we love a little enigma ๐ง
โ ๏ธ big one, bestie: this function is not atomic with respect to other threads in the process. threads may continue to execute while this function call is in the process of changing the scheduling policy and associated scheduling parameters for the underlying kernel-scheduled entities used by the process contention scope threads. so like, stuff is happening while other stuff is happening. multitasking era ๐
โญ RETURN VALUE โญ
upon successful completion, the function shall return the former scheduling policy of the specified process. (yes, the OLD one, not the new one โ read it twice, it's sneaky ๐ญ)
if the sched_setscheduler() function fails to complete successfully, the policy and scheduling parameters shall remain unchanged, and the function shall return a value of -1 and set errno to indicate the error.
๐ ERRORS ๐
the sched_setscheduler() function shall fail if:
EINVALโ the value of thepolicyparameter is invalid, or one or more of the parameters contained inparamis outside the valid range for the specified scheduling policy.EPERMโ the requesting process does not have permission to set either or both of the scheduling parameters or the scheduling policy of the specified process. (no permission, no party ๐ซ)ESRCHโ no process can be found corresponding to that specified bypid. she's not here, girl ๐
heads up: the following sections are informative. (that means they're vibes, not rules โจ)
๐ EXAMPLES ๐
None.
yes bestie, literally just None. we have no examples. it's a minimalist moment, we respect it ๐
๐ APPLICATION USAGE ๐
None.
again. None. no notes, no tips, no nothing. periodt.
๐ง RATIONALE ๐ง
None.
None. the reasoning is a mystery, the mystery is the reasoning. ๐ฆ
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
None. the future is... unspecified. fitting, honestly. โจ
๐ SEE ALSO ๐
- Scheduling Policies
sched_getparam()sched_getscheduler()sched_setparam()
and from the Base Definitions volume of POSIX.1โ2017: <sched.h>
๐ COPYRIGHT ๐
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole page bestie, you ate that ๐ซถ this iconic lil manual came to you from IEEE/The Open Group, 2017 โ mwah, stan, and remember: read your errno, know your policies, and never pass a negative pid ๐
โจ๐ธ
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms