经常感受系统资源不够用,一台机子上跑了不下3个比较重要的服务,可是天天咱们还要在上面进行个备份压缩等处理,网络长时间传输,这在就很影响本就不够用的系统资源;linux
这个时候咱们就能够把一些不过重要的好比copy/备份/同步等工做限定在一颗cpu上,或者是多核的cpu的一颗核心上进行处理,虽然这不必定是最有效的方法,但能够最大程度上利用了有效资源,下降那些不过重要的进程占用cpu资源;网络
查看系统下cpu信息:ide
#cat /proc/cpuinfo工具
taskset就能够帮咱们完成这项工做,并且操做很是简单;ui
该工具系统默认安装,rpm包名util-linuxthis
#taskset --help
taskset (util-linux 2.13-pre7)
usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]
set or get the affinity of a processorm
-p, –pid operate on existing given pid
-c, –cpu-list display and specify cpus in list format
-h, –help display this help
-v, –version output version information进程
举例:
一、开启一个只用0标记的cpu核心的新进程(job.sh是你的工做脚本)ci
#taskset -c 0 sh job.sh资源
二、查找现有的进程号,调整该进程cpu核心使用状况(23328举例用的进程号)
#taskset -pc 0 23328
pid 23328's current affinity list: 0-3 #0-3表示使用全部4核进行处理
pid 23328's new affinity list: 0 #调整后改成仅适用0标记单核处理
三、可在top中进行负载check
最后你能够在你的工做脚本中加入该指令来合理利用现有的cpu资源;