sched_getcpu(3)
๐ NAME ๐
sched_getcpu โ bestie, this literally tells you which CPU your calling thread is running on right now. Like a "where am I" but for silicon. โจ
๐ LIBRARY ๐
Standard C library (libc, -lc). Miss thing lives in libc, so you already know her.
๐ SYNOPSIS ๐
#include <sched.h>
int sched_getcpu(void);
๐ฆ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
_sched_getcpu():
- Since glibc 2.14:
_GNU_SOURCE - Before glibc 2.14:
_BSD_SOURCE || _SVID_SOURCE
/* _GNU_SOURCE also suffices */
okay so yes, you have to define the right macro or glibc will simply not let you in the group chat. that's just how it is ๐ซถ
๐ธ DESCRIPTION ๐ธ
sched_getcpu() returns the number of the CPU on which the calling thread is currently executing.
that's it. that's the whole function. it's giving "one job and she ate" ๐
โญ RETURN VALUE โญ
- On success: a nonnegative CPU number. slay, you found out where you live. ๐
- On error:
-1is returned anderrnois set to indicate the error. ๐ญ
๐ ERRORS ๐
ENOSYSโ this kernel does not implementgetcpu(2). bestie the kernel said no, and honestly? rude.
๐ฅ ATTRIBUTES ๐ฅ
For an explanation of the terms used in this section, see attributes(7).
- Interface:
sched_getcpu() - Attribute: Thread safety
- Value:
MT-Safe
MT-Safe means multiple threads can call her at the same time with zero drama. iconic behavior, no notes. ๐
๐ STANDARDS ๐
GNU. we're doing GNU things. periodt.
๐ง HISTORY ๐ง
glibc 2.6. so she's been here since 2007, aging like fine wine, lowkey a legend.
๐ NOTES ๐
okay so the call
cpu = sched_getcpu();
is equivalent to the following getcpu(2) call:
int c, s;
s = getcpu(&c, NULL);
cpu = (s == -1) ? s : c;
literally the same vibe, just a glow-up wrapper. iykyk ๐
๐ SEE ALSO ๐
that's the whole page bestie, go forth and know which CPU loves you back ๐
Linux man-pages 6.20, dated 2025-05-17 โ mwah, that's the source and the date, sign-off done, no cap ๐ซถโจ
๐ฆ 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: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms