---
name: "sched_getcpu"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/sched_getcpu"
---

# sched\_getcpu(3)

get current CPU

## NAME

**sched\_getcpu** – get current CPU

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sched.h\>**

*int*\

**sched\_getcpu**(*void*);

## DESCRIPTION

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)](/cpuset/2.md) and CPU affinity calls.

There are no error values as **sched\_getcpu**() does not fail.

## SEE ALSO

[cpuset(2)](/cpuset/2.md), [cpuset\_getaffinity(2)](/cpuset_getaffinity/2.md), [cpuset\_setaffinity(2)](/cpuset_setaffinity/2.md), [pthread\_getaffinity\_np(3)](/pthread_getaffinity_np/3.md), pthread\_setaffinity\_np

## 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.
