zoukankan      html  css  js  c++  java
  • 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

     

     

  • 相关阅读:
    js 操作文件
    Thymeleaf在js中使用表达式
    JUnit5常用注解
    .Net开发步骤
    springboot自定义 HandlerMapping
    期末加分+总结
    SAP ABAP 性能优化技巧 – 修改一组纪录
    SAP ABAP 性能优化技巧 – 视图取代基本表
    Sql Server 日期格式化函数 (转)
    SAP ABAP 性能优化技巧 — 使用二分查找(Binary Search)选项
  • 原文地址:https://www.cnblogs.com/kelamoyujuzhen/p/10108713.html
Copyright © 2011-2022 走看看