1SCHED_GETCPU(3) Linux Programmer's Manual SCHED_GETCPU(3)
2
3
4
6 sched_getcpu - determine CPU on which the calling thread is running
7
9 #include <sched.h>
10
11 int sched_getcpu(void);
12
13 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15 sched_getcpu():
16 Since glibc 2.14:
17 _GNU_SOURCE
18 Before glibc 2.14:
19 _BSD_SOURCE || _SVID_SOURCE
20 /* _GNU_SOURCE also suffices */
21
23 sched_getcpu() returns the number of the CPU on which the calling
24 thread is currently executing.
25
27 On success, sched_getcpu() returns a nonnegative CPU number. On error,
28 -1 is returned and errno is set to indicate the error.
29
31 ENOSYS This kernel does not implement getcpu(2).
32
34 This function is available since glibc 2.6.
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 └───────────────┴───────────────┴─────────┘
46 sched_getcpu() is glibc-specific.
47
49 The call
50
51 cpu = sched_getcpu();
52
53 is equivalent to the following getcpu(2) call:
54
55 int c, s;
56 s = getcpu(&c, NULL, NULL);
57 cpu = (s == -1) ? s : c;
58
60 getcpu(2), sched(7)
61
63 This page is part of release 5.10 of the Linux man-pages project. A
64 description of the project, information about reporting bugs, and the
65 latest version of this page, can be found at
66 https://www.kernel.org/doc/man-pages/.
67
68
69
70Linux 2017-09-15 SCHED_GETCPU(3)