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

相关推荐
七歌杜金房3 小时前
我终于又有了自己的 Linux 电脑
linux·debian·mac
倔强的石头_6 小时前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
SelectDB8 小时前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
tntxia1 天前
linux curl命令详解_curl详解
linux
扛枪的书生1 天前
Linux 网络管理器用法速查
linux
顺风尿一寸1 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
jiayou641 天前
KingbaseES 表级与列级加密完全指南
数据库·后端
XIAOHEZIcode2 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫2 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
GBASE2 天前
G术时刻 |GBase 8s数据库事务并发控制之封锁技术介绍(下)
数据库