← 返回命令列表

Linux command

taskset 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Get

taskset -p -c [pid]

Set

taskset -p -c [cpu_id] [pid]

Start

taskset -c [cpu_id] [command]

Start

taskset -c [cpu_id_1,cpu_id_2,cpu_id_3] [command]

Start

taskset -c [1-4] [command]

Set affinity using a hex bitmask

taskset -p [0x3] [pid]

Set affinity for all threads

taskset -a -p -c [0-3] [pid]

说明

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.

参数

-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

FAQ

What is the taskset command used for?

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.

How do I run a basic taskset example?

Run `taskset -p -c [pid]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -p, --pid do in taskset?

Operate on an existing PID