在Linux上,如何检查进程及其线程的CPU亲和性?

Linux上,如何检查进程及其线程的cpu亲和性?

解决方法

这很简单.收集所有进程ID和线程ID,然后调用taskset.
pname="java"  # for example
for pid in $(pgrep "${pname}")
do 
    [ "${pid}" != "" ] || exit
    echo "PID: ${pid}"
    for tid in \
      $(ps --no-headers -ww -p "${pid}" -L -olwp | sed 's/$/ /' | tr  -d '\n')
    do
    taskset -cp "${tid}"   # substitute thread id in place of a process id
    done
done

输出

PID: 15695
pid 15695's current affinity list: 0
pid 15696's current affinity list: 0
pid 15697's current affinity list: 0
...

这不是一个简单的单行的原因是因为pgrep命令不能返回线程ID(只有进程ID).我们使用命令ps –no-headers -ww -p“${pid}”-L -olwp做了一些额外的工作

在Ubuntu 12上测试,bash 4.

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...