Query the number of CPU cores in Linux

藏色散人
Release: 2019-08-19 14:40:38
forward
3186 people have browsed it

下面给大家介绍在 Linux 中查询 CPU 的核数的方法,希望对需要的朋友有所帮助,更多Linux使用教程可直接访问Linux视频教程进行学习!

Query the number of CPU cores in Linux

以一台 Linux 服务器为例。这台 Linux 包括两颗 Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz CPU, 单颗 CPU 包括 10 个 cpu core, 使用超线程包含 20 个逻辑 cpu core, 具体的官方介绍:E5-2630 V4

下面让我们通过 Linux 的命令来查找对应的参数,看看是否符合官方的介绍,主要是查看 /proc/cpuinfo 的信息获得。

查看 CPU 的型号

cat /proc/cpuinfo | grep 'model name' | sort | uniq
Copy after login
输出: model name : Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
Copy after login

查看 CPU 颗数

实际 Server 中插槽上的 CPU 个数,物理 cpu 数量,可以数不重复的 physical id 个数。

cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l
Copy after login

输出: 2

查看 CPU 核数

一颗 CPU 上面能处理数据的芯片组的数量。

cat /proc/cpuinfo |grep "cores"|uniq|awk '{print $4}'
Copy after login
输出: 10
Copy after login

逻辑 CPU 核数

一般情况,我们认为一颗 cpu 可以有多核,加上 intel 的超线程技术 (HT), 可以在逻辑上把一个物理线程模拟出两个线程来使用,使得单个核心用起来像两个核一样,以充分发挥 CPU 的性能,

逻辑 CPU 数量 = 物理 cpu 数量 x cpu cores 这个规格值 x 2(如果支持并开启超线程)。

top 命令查询出来的就是逻辑 CPU 的数量。

cat /proc/cpuinfo |grep "processor"|wc -l
Copy after login
输出:40
Copy after login

The above is the detailed content of Query the number of CPU cores in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!