Linux命令——taskset

参考:Linux taskset Command Tutorial for Beginners (with Examples)

简介

taskset命令用于设置进程(或 线程)的处理器亲和性(Processor Affinity),可以将进程(或 线程)绑定到特定的一个 或 多个CPU上去执行,而不允许将进程(或 线程)调度到其他的CPU上。

使用场景举例

查看具体某一进程(或 线程)的处理器亲和性

使用参数-p

本例中去观察的是qemu-kvm进程 和 vCPU线程

[root@localhost ~]# ps -eLf | grep qemu
root       1389   1339   1389  0    3 14:48 pts/0    00:00:10 /usr/libexec/qemu-kvm -cpu SandyBridge -vnc 0.0.0.0:1 centos1708.img
root       1389   1339   1393  2    3 14:48 pts/0    00:00:36 /usr/libexec/qemu-kvm -cpu SandyBridge -vnc 0.0.0.0:1 centos1708.img
root       1389   1339   1395  0    3 14:48 pts/0    00:00:00 /usr/libexec/qemu-kvm -cpu SandyBridge -vnc 0.0.0.0:1 centos1708.img
root       2638   1409   2638  0    1 15:10 pts/1    00:00:00 grep --color=auto qemu
[root@localhost ~]# taskset -p 1393
pid 1393's current affinity mask: ff
[root@localhost ~]# taskset -p 1389
pid 1389's current affinity mask: ff

输出结构处理器亲和性掩码是ff,表示进程(或 线程)可以在Host上让任何一个CPU运行。查看进程(或 线程)允许允许CPU范围使用-c参数。由于我的Host CPU是4核2线程,因此有8颗逻辑CPU。

[root@localhost ~]# taskset -cp 1393
pid 1393's current affinity list: 0-7
[root@localhost ~]# taskset -cp 1389
pid 1389's current affinity list: 0-7

更改具体某一进程(或 线程)CPU亲和性

taskset  -p   hexadecimal mask  PID/LWP

上面1393号线程可以在0~7号CPU之间允许,现在设置掩码0x11(二进制0001 0001),表示可以在0~4号CPU上允许。

[root@localhost ~]# taskset -p 0x11  1393
pid 1393's current affinity mask: ff
pid 1393's new affinity mask: 11
[root@localhost ~]# taskset -p   1393
pid 1393's current affinity mask: 11
[root@localhost ~]# taskset -cp   1393
pid 1393's current affinity list: 0,4

为具体某一进程(或 线程)CPU亲和性指定一组范围

使用-c参数

[root@localhost ~]# taskset -cp 0,3  1393
pid 1393's current affinity list: 0,4
pid 1393's new affinity list: 0,3
[root@localhost ~]# taskset -cp   1393
pid 1393's current affinity list: 0,3

 

 

 

转载于:https://www.cnblogs.com/kelamoyujuzhen/p/10108713.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值