LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

taskset

Set process CPU affinity

TLDR

Show which CPUs a running process is allowed to use
$ taskset --pid --cpu-list [pid]
copy
Pin a running process to one CPU
$ taskset --pid --cpu-list [2] [pid]
copy
Pin every thread of the process, not just the main one
$ taskset --all-tasks --pid --cpu-list [0-3] [pid]
copy
Launch a command pinned to a single CPU
$ taskset --cpu-list [0] [command]
copy
Launch a command pinned to a range of CPUs
$ taskset --cpu-list [0-3] [command]
copy
Launch a command pinned to a non-contiguous set
$ taskset --cpu-list [0,2,4] [command]
copy
Use a hexadecimal mask instead of a list
$ taskset [0x3] [command]
copy
Read a process's affinity as a mask
$ taskset --pid [pid]
copy

SYNOPSIS

taskset [options] [mask|list] [pid|command]

DESCRIPTION

taskset retrieves or sets a process's CPU affinity, which controls which CPUs the process can run on. CPU affinity can be specified as a bitmask or a comma-separated list of CPU IDs.This is useful for performance tuning, isolating processes to specific cores, or testing how software behaves on limited CPU resources.

PARAMETERS

-p, --pid

Operate on an existing PID
-c, --cpu-list
Specify CPUs as a list instead of a bitmask
-a, --all-tasks
Set/get affinity of all tasks (threads)
-h, --help
Display help information
-V, --version
Display version information

INSTALL

sudo apt install util-linux
copy
sudo dnf install util-linux
copy
sudo pacman -S util-linux
copy
sudo apk add util-linux-misc
copy
sudo zypper install util-linux
copy
brew install util-linux
copy
nix profile install nixpkgs#util-linux
copy

CAVEATS

CPU IDs start at 0. Setting affinity may not improve performance and can hurt it if done incorrectly. The kernel may still migrate processes for load balancing unless CPU isolation is configured. The CPU list supports stride syntax (e.g. 0-10:2 means CPUs 0,2,4,6,8,10). Part of the util-linux package.

SEE ALSO

chrt(1), nice(1), renice(1), numactl(8)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid