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() returns 0. slay. โœจ
  • On error, -1 is returned, and errno is 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_FIFO or SCHED_RR). That's her natural habitat. That's where she eats.
  • Using sched_yield() with nondeterministic scheduling policies such as SCHED_OTHER is 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms