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

相关推荐
cookqq16 分钟前
mongodb源码分析session异步接受asyncSourceMessage()客户端流变Message对象
数据库·sql·mongodb·nosql
呼拉拉呼拉28 分钟前
Redis故障转移
数据库·redis·缓存·高可用架构
什么都想学的阿超31 分钟前
【Redis系列 04】Redis高可用架构实战:主从复制与哨兵模式从零到生产
数据库·redis·架构
huangyuchi.33 分钟前
【Linux】LInux下第一个程序:进度条
linux·运维·服务器·笔记·进度条·c/c++
pp-周子晗(努力赶上课程进度版)1 小时前
【MySQL】视图、用户管理、MySQL使用C\C++连接
数据库·mysql
帽儿山的枪手1 小时前
程序员必掌握的iptables五表五链
linux·网络协议
斯特凡今天也很帅1 小时前
clickhouse常用语句汇总——持续更新中
数据库·sql·clickhouse
西阳未落1 小时前
Linux(14)——库的制作与原理
linux
444A4E2 小时前
深入Linux进程优先级:Nice值与O(1)调度器原理
linux·操作系统
Jooolin2 小时前
【编程史】Git是如何诞生的?这可并非计划之中...
linux·git·ai编程