ubuntu如何查看系统信息、cpu型号

查看当前操作系统内核信息

sh 复制代码
uname -a

输出:

Linux htu-H110M-S2 5.4.0-148-generic #165~18.04.1-Ubuntu SMP Thu Apr 20 01:14:06 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

查看当前操作系统发行版信息

sh 复制代码
cat /etc/issue

Ubuntu 18.04.6 LTS \n \l

查看cpu型号

sh 复制代码
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

4 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz

(看到有4个逻辑CPU, 也知道了CPU型号)

查看物理cpu颗数

sh 复制代码
cat /proc/cpuinfo | grep physical | uniq -c

1 physical id : 0

1 address sizes : 39 bits physical, 48 bits virtual

1 physical id : 0

1 address sizes : 39 bits physical, 48 bits virtual

1 physical id : 0

1 address sizes : 39 bits physical, 48 bits virtual

1 physical id : 0

1 address sizes : 39 bits physical, 48 bits virtual

2 physical id : 0

(说明实际上是1颗4核的CPU)

查看cpu运行模式

sh 复制代码
getconf LONG_BIT

64

查看cpu是否支持64bit

sh 复制代码
cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l

4

(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)

查看cpu信息概要:

sh 复制代码
lscpu

输出结果:

sh 复制代码
架构:           x86_64
CPU 运行模式:   32-bit, 64-bit
字节序:         Little Endian
CPU:             4
在线 CPU 列表:  0-3
每个核的线程数: 1
每个座的核数:   4
座:             1
NUMA 节点:      1
厂商 ID:        GenuineIntel
CPU 系列:       6
型号:           158
型号名称:       Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
步进:           9
CPU MHz:        800.126
CPU 最大 MHz:   3800.0000
CPU 最小 MHz:   800.0000
BogoMIPS:       6799.81
虚拟化:         VT-x
L1d 缓存:       32K
L1i 缓存:       32K
L2 缓存:        256K
L3 缓存:        6144K
NUMA 节点0 CPU: 0-3
标记:           fpu vme de ......

最后来个大而全的:

sh 复制代码
cat /proc/cpuinfo

输出结果:

sh 复制代码
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
stepping        : 9
microcode       : 0xf0
cpu MHz         : 800.034
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de ......
bugs            : cpu_meltdown spectre_v1 ...
bogomips        : 6799.81
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
stepping        : 9
microcode       : 0xf0
cpu MHz         : 800.110
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 4
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse......
bugs            : cpu_meltdown spectre_v1 ...
bogomips        : 6799.81
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
stepping        : 9
microcode       : 0xf0
cpu MHz         : 800.033
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 2
cpu cores       : 4
apicid          : 4
initial apicid  : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de ......
bugs            : cpu_meltdown spectre_v1 ...
bogomips        : 6799.81
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
stepping        : 9
microcode       : 0xf0
cpu MHz         : 800.033
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 3
cpu cores       : 4
apicid          : 6
initial apicid  : 6
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de ......
bugs            : cpu_meltdown spectre_v1 ...
bogomips        : 6799.81
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

linux下通过C语言获取CPU个数信息

c 复制代码
#include<stdio.h>
#include<unistd.h>

int main()
{
int cpu_num;

cpu_num = sysconf(_SC_NPROCESSORS_CONF);
printf("_SC_NPROCESSORS_CONF=%d/n",cpu_num);

cpu_num = sysconf(_SC_NPROCESSORS_ONLN);
printf("_SC_NPROCESSORS_ONLN=%d/n",cpu_num);

return 0;
}

/* 
* - _SC_NPROCESSORS_CONF
*       The number of processors configured.
* 
* - _SC_NPROCESSORS_ONLN
*       The number of processors currently online (available).
*/

Linux下获得CPU个数一个简单方法就是查看/proc/cpuinfo文件。

看出现processor字样的行数是多少条,即有多少个逻辑CPU(包括多核,超线程)。因此终端下输入下面命令即可:

sh 复制代码
cat /proc/cpuinfo | grep processor | wc -l

输出:4

相关推荐
Zzz 小生2 小时前
Claude Code学习笔记(四)-助你快速搭建首个Python项目
大数据·数据库·elasticsearch
liujing102329294 小时前
stm32大项目阶段20251015
linux
嵌入式郑工5 小时前
LINUX驱动开发: 设备和驱动是怎么匹配的?
linux·运维·服务器
nongcunqq5 小时前
abap 操作 excel
java·数据库·excel
zhuyan1085 小时前
【远程桌面】在ubuntu中安装远程桌面
ubuntu
rain bye bye6 小时前
calibre LVS 跑不起来 就将setup 的LVS Option connect下的 connect all nets by name 打开。
服务器·数据库·lvs
郭式云源生法则6 小时前
归档及压缩、重定向与管道操作和综合使用,find精确查找、find处理查找结果、vim高级使用、vimdiff多文件使用
linux·运维·服务器
一张假钞6 小时前
Ubuntu 24.04 安装 Jenkins
linux·ci/cd·jenkins
tuokuac6 小时前
查看你电脑上某个端口正在被哪个进程占用
linux
MANONGMN7 小时前
Linux 通配符与正则表达式(含实战案例+避坑指南)
linux·运维·正则表达式