sched_yield(2)
๐ฆ NAME ๐ฆ
okay so bestie, welcome to sched_yield(2) โ a lil section 2 system call, and today's vibe is giving the processor back. Yes, that's the whole personality. She yields. She shares. She's the communal friend of the kernel world. ๐
sched_yield โ yield the processor
๐ LIBRARY ๐
Standard C library, a.k.a. libc, -lc. The usual queen. ๐
โจ SYNOPSIS โจ
#include <sched.h>
int sched_yield(void);
no args, no drama, no notes. just vibes and a void. ๐ซถ
๐ธ DESCRIPTION ๐ธ
Okay so here's the tea, and it's actually very simple tea:
sched_yield() makes the calling thread relinquish the CPU. That's it, that's the whole function.
Then? The thread gets moved to the end of the queue for its static priority, and a new thread gets to run. It's giving "no bestie, you go first, I insist" but at the scheduler level. So polite. So iconic. ๐ง
๐ RETURN VALUE ๐
- On success,
sched_yield()returns0. slay. โจ - On error,
-1is returned, anderrnois set to indicate the error. (classic move, we love a consistent API)
๐ ERRORS ๐
ngl this section is short because there's literally nothing to say:
In the Linux implementation, sched_yield() always succeeds.
no errors. zero. none. she cannot fail. main character energy fr fr. ๐
๐ STANDARDS ๐
POSIX.1-2024. periodt. ๐
๐ HISTORY ๐
POSIX.1-2001โ but optional, which is a little rude of them honestly. ๐POSIX.1-2008โ and now she's here for real.
Also, important lore: before POSIX.1-2008, systems on which sched_yield() is available defined _POSIX_PRIORITY_SCHEDULING in <unistd.h>. so if you're out here reading ancient code, that's why that macro is haunting you. ๐ป
๐จ CAVEATS ๐จ
okay this is the part where I grab you by the shoulders. listen. listen listen listen. ๐ญ
sched_yield()is intended for use with real-time scheduling policies (i.e.,SCHED_FIFOorSCHED_RR). That's her natural habitat. That's where she eats.- Using
sched_yield()with nondeterministic scheduling policies such asSCHED_OTHERis unspecified, and โ and I'm quoting the elders here โ very likely means your application design is broken. not me saying it. the manpage saying it. ๐ - If the calling thread is the only thread in the highest priority list at that time, it will continue to run after a call to
sched_yield(). so you yielded and gotโฆ yourself back. a round trip to nowhere. congrats bestie. ๐ - Avoid calling
sched_yield()unnecessarily or inappropriately (e.g., when resources needed by other schedulable threads are still held by the caller), since doing so will result in unnecessary context switches, which will degrade system performance. like, don't do it for fun. it's not a fidget toy. ๐ฅ
fr fr, this call is a scalpel, not a snack. use it where it belongs or the whole system gets sluggish and sad. ๐ญ
๐ SEE ALSO ๐
and that's the whole page, bestie!! you now know everything the kernel wanted you to know about yielding. go forth, yield responsibly, and remember โ this one came to you courtesy of Linux man-pages 6.20, dated 2026-02-08, on the sched_yield(2) page. 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