Centos下如何为进程绑定CPU?Centos下为进程绑定CPU的方法

发布时间:2022-05-02 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Centos下如何为进程绑定CPU?Centos下为进程绑定CPU的方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

taskset 是一个CPU 调节工具,能够将系统任务分配至指定的CPU

本文以nodejs为例

第一步,查询nodejs 进程

pgrep node

19277

19283

第二步,锁定CPU

taskset -pc 0 19277 (其中0代表CPU0,以此类推)

taskset -pc 1 19283

第三步,搞定

附一个小脚本,能自动绑定nodejs的进程,假设有四个node,CPU是四核的。

#!/usr/bin/env bash

set-e

node_porcess=`pgrep node|wc-l`

if[$node_PRocess -eq0 ];then

echo“nodejs process not found”

exIT1

else

node1=`pgrep node |sort|tr-s "\n"" "|awk'{print $1}'`

node2=`pgrep node |sort|tr-s "\n"" "|awk'{print $2}'`

node3=`pgrep node |sort|tr-s "\n"" "|awk'{print $3}'`

node4=`pgrep node |sort|tr-s "\n"" "|awk'{print $4}'`

taskset -pc 0 $node1

taskset -pc 1 $node2

taskset -pc 2 $node3

taskset -pc 3 $node4

fi

脚本宝典总结

以上是脚本宝典为你收集整理的Centos下如何为进程绑定CPU?Centos下为进程绑定CPU的方法全部内容,希望文章能够帮你解决Centos下如何为进程绑定CPU?Centos下为进程绑定CPU的方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: