ps_get_cpu_affinity: Query or set CPU affinity

View source: R/low-level.R

ps_get_cpu_affinityR Documentation

Query or set CPU affinity

Description

ps_get_cpu_affinity() queries the CPU affinity of a process. ps_set_cpu_affinity() sets the CPU affinity of a process.

Usage

ps_get_cpu_affinity(p = ps_handle())

ps_set_cpu_affinity(p = ps_handle(), affinity)

Arguments

p

Process handle.

affinity

Integer vector of CPU numbers to restrict a process to. CPU numbers start with zero, and they have to be smaller than the number of (logical) CPUs, see ps_cpu_count().

Details

CPU affinity consists in telling the OS to run a process on a limited set of CPUs only (on Linux cmdline, the taskset command is typically used).

These functions are only supported on Linux and Windows. They error on macOS.

Value

ps_get_cpu_affinity() returns an integer vector of CPU numbers, starting with zero.

ps_set_cpu_affinity() returns NULL, invisibly.

Examples


# current
orig <- ps_get_cpu_affinity()
orig

# restrict
ps_set_cpu_affinity(affinity = 0:0)
ps_get_cpu_affinity()

# restore
ps_set_cpu_affinity(affinity = orig)
ps_get_cpu_affinity()


r-lib/ps documentation built on April 2, 2024, 4:09 p.m.