如何从命令行获取 Linux 中的 CPU/内核数? [英] How to obtain the number of CPUs/cores in Linux from the command line?
本文介绍了如何从命令行获取 Linux 中的 CPU/内核数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个脚本,但我不知道如何获取打印输出中的最后一个元素:
I have this script, but I do not know how to get the last element in the printout:
cat /proc/cpuinfo | awk '/^processor/{print $3}'
最后一个元素应该是 CPU 的数量,减 1.
The last element should be the number of CPUs, minus 1.
推荐答案
grep -c ^processor /proc/cpuinfo
将计算以processor"开头的行数;在 /proc/cpuinfo
will count the number of lines starting with "processor" in /proc/cpuinfo
对于具有超线程的系统,您可以使用
For systems with hyper-threading, you can use
grep ^cpu\scores /proc/cpuinfo | uniq | awk '{print $4}'
哪个应该返回(例如)8
(而上面的命令将返回16
)
which should return (for example) 8
(whereas the command above would return 16
)
这篇关于如何从命令行获取 Linux 中的 CPU/内核数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文