taskset
process managementLinux
The taskset command is one of the most frequently used commands in Linux/Unix-like operating systems. taskset Set or retrieve a process's CPU affinity
Quick Reference
Command Name:
taskset
Category:
process management
Platform:
Linux
Basic Usage:
taskset [options] [arguments]
Common Use Cases
Syntax
taskset [options] mask command [argument...] taskset [options] -p [mask] pid
Options
Option | Description |
---|---|
-a, --all-tasks |
Set or retrieve the CPU affinity of all tasks (threads) of the specified process |
-c, --cpu-list |
Specify CPUs by a comma-separated list or range of CPU numbers instead of a mask |
-p, --pid |
Operate on an existing process instead of launching a new command |
-h, --help |
Display help information and exit |
-V, --version |
Display version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the taskset
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
Start a new process with CPU affinity set to CPU 0
taskset 0x1 command arg1 arg2
Set CPU affinity of an existing process to CPU 0 and CPU 1
taskset -p 0x3 1234
View the current CPU affinity of a process
taskset -p 1234
Advanced Examples:
Start a process on specific CPUs using hexadecimal mask
taskset 0x5 ./cpu-intensive-process
Start a process on specific CPUs using decimal mask
taskset 10 ./cpu-intensive-process
Run a process on all CPUs except CPU 0
taskset -c 1-7 ./application