sched_getcpu(3)

sched_getcpu3

Get current cpu

Usage

#include <sched.h>

int

sched_getcpu(void);

Library

Standard C Library (libc, -lc)

Overview

The sched_getcpu() function returns the current CPU on which the calling thread is running.

Return values

sched_getcpu() returns the 0-based index of the current CPU at the time of the call. The value may become invalid immediately after return, unless the thread is pinned to a specific CPU. CPU numbering is the same as used by cpuset(2) and CPU affinity calls.

There are no error values as sched_getcpu() does not fail.

Releases

Unchanged in 6 releases since FreeBSD 14.3-RELEASE.

  1. 14.3–16.0

Standards

The sched_getcpu function originated in Linux. This implementation aims to be source-compatible with the Linux implementation.

History

The sched_getcpu function was introduced in FreeBSD 13.1.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.