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

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

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

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

cat /etc/issue

Ubuntu 18.04.6 LTS \n \l

查看cpu型号

cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

4 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
(看到有4个逻辑CPU, 也知道了CPU型号)

查看物理cpu颗数

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运行模式

getconf LONG_BIT

64

查看cpu是否支持64bit

cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l

4

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

查看cpu信息概要:

lscpu

输出结果:

架构:           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 ......

最后来个大而全的:

cat /proc/cpuinfo

输出结果:

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个数信息

#include
#include

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(包括多核,超线程)。因此终端下输入下面命令即可:

cat /proc/cpuinfo | grep processor | wc -l

输出:4

你可能感兴趣的:(Linux,ubuntu,数据库,linux)