利用taskset命令,将某进程绑定到某个CPU上

本文介绍如何使用 taskset 工具设置 Linux 进程的 CPU 亲和性,包括基本用法、参数说明及实际操作示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
taskset (util-linux-ng 2.17.2)
usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]
set or get the affinity of a process
  -p, --pid                  operate on existing given pid
  -c, --cpu-list             display and specify cpus in list format
  -h, --help                 display this help
  -V, --version              output version information
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

例:

将pid号为2181的进程绑定到cpu0上:

1
2
3
[root@Centos ~]# taskset -cp 0 2181
pid 2181's current affinity list: 0
pid 2181's new affinity list: 0

将pid号为2181的进程绑定到几个cpu上:

1
[root@Centos ~]# taskset -cp 0,1 2181  --绑定到cpu0和cpu1上









本文转自 SoulMio 51CTO博客,原文链接:http://blog.51cto.com/bovin/1926384,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值