linux - 使用任务集在 Linux 上的处理器关联

标签 linux bash ubuntu cpu taskset

我在 bash 脚本中有以下代码:

echo "bash pid => $$";
echo "processor affinity before => $(taskset -p $$)"
taskset -cp ${AN_INTEGER} $$
echo "processor affinity after => $(taskset -p $$)"

我得到这个输出:

processor affinity before => pid 5047's current affinity mask: ff
pid 5047's current affinity list: 0-7
pid 5047's new affinity list: 1
processor affinity after => pid 5047's current affinity mask: 2

谁知道这是什么意思?

我开始搞乱处理器亲和性的原因是因为我会启动多个 bash 子进程,而所有 bash 子进程亲和性的值都是“ff”,所以看起来它们都以同一个 CPU 为目标。

最佳答案

affinity ma​​sk 控制进程可以运行的 处理器 - 而不是单个特定处理器。此掩码中为 1 的位表示进程可以在其上运行的处理器。由于您指定希望此进程仅在 CPU 1 上运行,因此关联掩码现在为 0b00000010 或 2。

关于linux - 使用任务集在 Linux 上的处理器关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46147110/

相关文章:

ruby - 使用 Chef 安装 rpm 包

linux - wget:非 http URL 上不支持的方案

c - 为什么在成为孤立进程组时未收到 SIGHUP 信号

linux - 精确地使用两个参数搜索 grep

php - 带有 Nginx 1.6.2 和 PHP 5.6.4 的 Ubuntu 14.04 上的 502 Bad Gateway

c++ - Linux C++ 文件权限被拒绝

bash - 使用 bash 的 Perl 反引号

bash - 设置具有空格mac的环境变量

Ubuntu 上的 Apache : module dav_module is already loaded

linux - 在 Ubuntu 主机上运行 Ubuntu Docker 镜像是否比在任何其他操作系统上运行相同的 Docker 镜像运行得更快?