1.\" SPDX-License-Identifier: BSD-2-Clause 2.\" 3.\" Copyright (c) 2024 The FreeBSD Foundation 4.\" 5.\" This documentation was written by Ed Maste <emaste@FreeBSD.org> 6.\" under sponsorship from the FreeBSD Foundation. 7.\" 8.Dd November 13, 2024 9.Dt SCHED_GETCPU 3 10.Os 11.Sh NAME 12.Nm sched_getcpu 13.Nd get current CPU 14.Sh LIBRARY 15.Lb libc 16.Sh SYNOPSIS 17.In sched.h 18.Ft int 19.Fn sched_getcpu void 20.Sh DESCRIPTION 21The 22.Fn sched_getcpu 23function returns the current CPU on which the calling thread is running. 24.Sh RETURN VALUES 25.Fn sched_getcpu 26returns the 0-based index of the current CPU at the time of the call. 27The value may become invalid immediately after return, unless the thread is 28pinned to a specific CPU. 29CPU numbering is the same as used by 30.Xr cpuset 2 31and CPU affinity calls. 32.Pp 33There are no error values as 34.Fn sched_getcpu 35does not fail. 36.Sh SEE ALSO 37.Xr cpuset 2 , 38.Xr cpuset_getaffinity 2 , 39.Xr cpuset_setaffinity 2 , 40.Xr pthread_getaffinity_np 3 , 41.Xr pthread_setaffinity_np 42.Sh STANDARDS 43The 44.Nm 45function originated in Linux. 46This implementation aims to be source-compatible with the Linux implementation. 47.Sh HISTORY 48The 49.Nm 50function was introduced in 51.Fx 13.1 . 52