1sched_getcpu(3) Library Functions Manual sched_getcpu(3)
2
3
4
6 sched_getcpu - determine CPU on which the calling thread is running
7
9 Standard C library (libc, -lc)
10
12 #include <sched.h>
13
14 int sched_getcpu(void);
15
16 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18 sched_getcpu():
19 Since glibc 2.14:
20 _GNU_SOURCE
21 Before glibc 2.14:
22 _BSD_SOURCE || _SVID_SOURCE
23 /* _GNU_SOURCE also suffices */
24
26 sched_getcpu() returns the number of the CPU on which the calling
27 thread is currently executing.
28
30 On success, sched_getcpu() returns a nonnegative CPU number. On error,
31 -1 is returned and errno is set to indicate the error.
32
34 ENOSYS This kernel does not implement getcpu(2).
35
37 For an explanation of the terms used in this section, see at‐
38 tributes(7).
39
40 ┌────────────────────────────────────────────┬───────────────┬─────────┐
41 │Interface │ Attribute │ Value │
42 ├────────────────────────────────────────────┼───────────────┼─────────┤
43 │sched_getcpu() │ Thread safety │ MT-Safe │
44 └────────────────────────────────────────────┴───────────────┴─────────┘
45
47 GNU.
48
50 glibc 2.6.
51
53 The call
54
55 cpu = sched_getcpu();
56
57 is equivalent to the following getcpu(2) call:
58
59 int c, s;
60 s = getcpu(&c, NULL, NULL);
61 cpu = (s == -1) ? s : c;
62
64 getcpu(2), sched(7)
65
66
67
68Linux man-pages 6.04 2023-03-30 sched_getcpu(3)