sched_getaffinity Linux system call

Read the CPU set on which a thread is allowed to run.

In Linux 7.3, sched_getaffinity is defined in the system call table of 12 of the 12 bundled ABIs.

Number on each ABI Linux 7.3

sched_getaffinity in the Linux 7.3 system call tables
ABINo.HexEntry pointInstructionNRArgument locationsKernel tableInteractive view
x86-642040xccsys_sched_getaffinitysyscallraxrdi, rsi, rdx, r10, r8, r9syscall_64.tbl:216Open
i3862420xf2sys_sched_getaffinity compat: compat_sys_sched_getaffinityint 0x80eaxebx, ecx, edx, esi, edi, ebpsyscall_32.tbl:257Open
AArch641230x7bsys_sched_getaffinity compat: compat_sys_sched_getaffinitysvc #0x8x0, x1, x2, x3, x4, x5syscall.tbl:158Open
ARM EABI2420xf2sys_sched_getaffinitysvc #0r7r0, r1, r2, r3, r4, r5syscall.tbl:260Open
RISC-V 641230x7bsys_sched_getaffinity compat: compat_sys_sched_getaffinityecalla7a0, a1, a2, a3, a4, a5syscall.tbl:158Open
LoongArch 641230x7bsys_sched_getaffinity compat: compat_sys_sched_getaffinitysyscall 0a7a0, a1, a2, a3, a4, a5syscall.tbl:158Open
PowerPC 642230xdfsys_sched_getaffinity compat: compat_sys_sched_getaffinityscr0r3, r4, r5, r6, r7, r8syscall.tbl:285Open
PowerPC 322230xdfsys_sched_getaffinity compat: compat_sys_sched_getaffinityscr0r3, r4, r5, r6, r7, r8syscall.tbl:285Open
IBM Z (s390x)2400xf0sys_sched_getaffinitysvc 0r1r2, r3, r4, r5, r6, r7syscall.tbl:197Open
MIPS o3242400x1090sys_sched_getaffinity compat: compat_sys_sched_getaffinitysyscallv0a0, a1, a2, a3, Stack (5), Stack (6)syscall_o32.tbl:254Open
MIPS n3261960x1834compat_sys_sched_getaffinitysyscallv0a0, a1, a2, a3, a4, a5syscall_n32.tbl:207Open
MIPS n6451960x144csys_sched_getaffinitysyscallv0a0, a1, a2, a3, a4, a5syscall_n64.tbl:207Open

Argument locations are the ABI’s calling convention for ARG1–ARG6 in order, not an assignment made for this call. On 32-bit ABIs, 64-bit values may occupy multiple registers and require alignment; assembly wrappers may reorder them. See syscall(2). A table entry does not mean the call exists in every kernel: most optional calls return ENOSYS when the matching configuration option or architecture support is not built.

Kernel declaration

asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, unsigned long __user *user_mask_ptr);

x86-64, i386, AArch64, ARM EABI, RISC-V 64, LoongArch 64, PowerPC 64, PowerPC 32, IBM Z (s390x), MIPS o32, MIPS n64 · Declaration: include/linux/syscalls.h:659

asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len, compat_ulong_t __user *user_mask_ptr);

MIPS n32 · Declaration: include/linux/compat.h:701

Signatures are kernel declarations and may differ from the C library wrappers.

Manual page

sched_setaffinity(2)

Bundled kernel releases

Bundled releases whose tables define sched_getaffinity
ReleaseABIs bundledDefined in the table of
Linux 7.312all 12
Linux 6.1812all 12
Linux 6.1212all 12
Linux 6.612all 12
Linux 5.1912all 12
Linux 4.155all 5
Linux 3.74all 4
Linux 3.03all 3
Linux 2.6.243all 3
Linux 2.6.163all 3
Linux 2.6.122all 2
Linux 1.01none

Each release is a separate snapshot, and older releases bundle fewer ABIs. This table does not claim the release in which the call first appeared. Numbers are listed where a release differs from Linux 7.3.