taskset command
linux의 taskset
명령어(CLI)는 프로세스의 CPU 선호도(affinity)를 설정하거나 찾는 명령어 입니다.
간단하게 말하면 프로세스가 동작할 때 CPU(CPU or Core)를 지정하는 명령어 입니다.
기본 사용법
# CPU 0번째(1번) Core를 통해 프로세스를 실행하기
$> taskset -c 0 ./process
taskset help
$> taskset --help
Usage: taskset [options] [mask | cpu-list] [pid|cmd [args...]]
Show or change the CPU affinity of a process.
Options:
-a, --all-tasks operate on all the tasks (threads) for a given pid
-p, --pid operate on existing given pid
-c, --cpu-list display and specify cpus in list format
-h, --help display this help
-V, --version display version
The default behavior is to run a new command:
taskset 03 sshd -b 1024
You can retrieve the mask of an existing task:
taskset -p 700
Or set it:
taskset -p 03 700
List format uses a comma-separated list instead of a mask:
taskset -pc 0,3,7-11 700
Ranges in list format can take a stride argument:
e.g. 0-31:2 is equivalent to mask 0x55555555
For more details see taskset(1).
TLDR
$> tldr taskset
taskset
Get or set a process' CPU affinity or start a new process with a defined CPU affinity.
More information: https://manned.org/taskset.
- Get a running process' CPU affinity by PID:
taskset --pid --cpu-list pid
- Set a running process' CPU affinity by PID:
taskset --pid --cpu-list cpu_id pid
- Start a new process with affinity for a single CPU:
taskset --cpu-list cpu_id command
- Start a new process with affinity for multiple non-sequential CPUs:
taskset --cpu-list cpu_id_1,cpu_id_2,cpu_id_3
- Start a new process with affinity for CPUs 1 through 4:
taskset --cpu-list cpu_id_1-cpu_id_4