sched.h(7POSIX)

πŸŽ€ sched.h(7POSIX) πŸŽ€

okay bestie, welcome to the POSIX Programmer's Manual β€” this one is sched.h(7POSIX), aka execution scheduling, and it's genuinely one of those headers that runs the whole vibe of your machine. sit down, grab a strawberry drink πŸ“, we're doing this.


✨ PROLOG ✨

okay so first things first, real talk: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so go consult the corresponding Linux manual page for the deets on Linux behavior), or β€” plot twist β€” the interface may not be implemented on Linux at all. πŸ™ˆ


πŸ’– NAME πŸ’–

sched.h β€” execution scheduling. that's the whole name. short, iconic, does exactly what it says. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <sched.h>

that's it. that's the door. walk through it. πŸšͺ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea. the <sched.h> header shall define the pid_t type, exactly as described in <sys/types.h>.

it shall also define the time_t type, as described in <sys/types.h>.

and it shall define the timespec structure, as described in <time.h>.

then we get to the good part: the header shall define the sched_param structure, which shall include the scheduling parameters required for implementation of each supported scheduling policy. this structure shall include at least this member:

int       sched_priority        Process or thread execution scheduling priority.

and the sched_param structure defined in <sched.h> shall include these members in addition to the ones above β€” so yes, it's giving expanded edition:

int             sched_ss_low_priority Low scheduling priority for
                                      sporadic server.
struct timespec sched_ss_repl_period  Replenishment period for
                                      sporadic server.
struct timespec sched_ss_init_budget  Initial budget for sporadic server.
int             sched_ss_max_repl     Maximum pending replenishments for
                                      sporadic server.

so the way this works: every process or thread is controlled by an associated scheduling policy and priority. associated with each policy is a priority range. each policy definition specifies the minimum priority range for that policy. and β€” important β€” the priority ranges for each policy may overlap the priority ranges of other policies. no gatekeeping. πŸ’…

four scheduling policies are defined; others may be defined by the implementation. the four standard policies are indicated by the values of these symbolic constants:

  • SCHED_FIFO β€” first in-first out (FIFO) scheduling policy.
  • SCHED_RR β€” round robin scheduling policy.
  • SCHED_SPORADIC β€” sporadic server scheduling policy.
  • SCHED_OTHER β€” another scheduling policy.

the values of these constants are distinct. no two the same, periodt.

the following shall be declared as functions and may also be defined as macros. function prototypes shall be provided:

int    sched_get_priority_max(int);
int    sched_get_priority_min(int);
int    sched_getparam(pid_t, struct sched_param *);
int    sched_getscheduler(pid_t);
int    sched_rr_get_interval(pid_t, struct timespec *);
int    sched_setparam(pid_t, const struct sched_param *);
int    sched_setscheduler(pid_t, int, const struct sched_param *);
int    sched_yield(void);
lowkey a whole friend group of syscalls right there 🫢

one more thing: inclusion of the <sched.h> header may make visible all symbols from the <time.h> header. surprise guests at the party. πŸŽ‰

the following sections are informative β€” meaning they're the commentary track, not the actual requirements.


🌈 APPLICATION USAGE 🌈

None.

literally nothing. the void. πŸ’€


🧚 RATIONALE 🧚

None.

also nothing! the vibes are immaculate and unexplained. ✨


⭐ FUTURE DIRECTIONS ⭐

None.

nothing coming down the pipeline either. it's stable, bestie. 🌸


πŸ”₯ SEE ALSO πŸ”₯

  • <sys_types.h>
  • <time.h>

and from the System Interfaces volume of POSIX.1‐2017:

  • sched_get_priority_max()
  • sched_getparam()
  • sched_getscheduler()
  • sched_rr_get_interval()
  • sched_setparam()
  • sched_setscheduler()
  • sched_yield()

go read those next, i'm obsessed with them actually. πŸ“šπŸ’œ


okay legal bestie moment, this part matters so read it fr fr:

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 .


no cap: if this page and the real Standard ever disagree, the Standard wins. it's the referee, not us. πŸ’…

and that's the page!! this one's brought to you by IEEE/The Open Group, 2017 β€” the source and the date of this whole thing. ty for coming to my ted talk, now go schedule something responsibly πŸ¦‹πŸ’–βœ¨