Linux查看物理CPU个数、核数、逻辑CPU个数

# 总核数 = 物理CPU个数 X 每颗物理CPU的核数

# 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

# 查看物理CPU个数

cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

# 查看每个物理CPU中core的个数(即核数) #【物理CPU内核的个数】(1个物理CPU里面有几个物理内核)

cat /proc/cpuinfo| grep "cpu cores"| uniq

”cpu cores“指的是一个物理CPU有几个核

# 查看逻辑CPU的个数

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

查看CPU信息(型号)  #【逻辑CPU数量和型号】

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

【物理CPU中逻辑CPU的个数】(如果不使用超线程技术,则此值和物理CPU内核数量一致;不一致则为整倍数)
cat /proc/cpuinfo | grep 'siblings' | uniq

“siblings”指的是一个物理CPU有几个逻辑CPU

【超线程】(分别输出cpu cores和siblings数量,使用超线程则后者翻倍)

cat /proc/cpuinfo | grep -e "cpu cores" -e "siblings" | sort | uniq

如何判断是否开启超线程

“超线程(Hyper-Threading,简称“HT”)”技术。超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的运行效率。

超线程技术是在一颗CPU同时执行多个程序而共同分享一颗CPU内的资源,理论上要像两颗CPU一样在同一时间执行两个线程,虽然采用超线程技术能同时执行两个线程,但它并不象两个真正的CPU那样,每个CPU都具有独立的资源。当两个线程都同时需要某一个资源时,其中一个要暂时停止,并让出资源,直到这些资源闲置后才能继续。因此超线程的性能并不等于两颗CPU的性能。

“siblings”指的是一个物理CPU有几个逻辑CPU

”cpu cores“指的是一个物理CPU有几个核

如果“siblings”和“cpu cores”一致,则说明不支持超线程,或者超线程未打开。
如果“siblings”是“cpu cores”的两倍,则说明支持超线程,并且超线程已打开。
是否为超线程?
如果有两个逻辑CPU具有相同的”core id”,那么超线程是打开的。

例如,如果系统包含两个物理封装,每个封装中又包含两个支持超线程(HT)技术的处理器内核,则 /proc/cpuinfo 文件将包含此数据。(注:数据并不在表格中。)

processor 0 4 2 6 1 5 3 7
physical id 0 0 0 0 1 1 1 1
core id 0 0 1 1 2 2 3 3
siblings 4 4 4 4 4 4 4 4
cpu cores 2 2 2 2 2 2 2 2

此例说明:
1)一个物理封装有四个内核,即有4个逻辑处理器。
2)一个内核上有2个不同的processer,即系统支持超线程技术(HT)。

值得注意的是physical id和core id的编号可能是也可能不是连续的。系统上有两个物理封装并不罕见,而且physical id可能等于0和3。

参考链接:https://www.cnblogs.com/hehehaha/p/6332269.html

cat /proc/cpu  全部输出

[machangwei@xxsx01 ~]$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 8
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 8
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 8
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 8
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 4
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 4
cpu cores : 8
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 5
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 5
cpu cores : 8
apicid : 5
initial apicid : 5
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 6
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 6
cpu cores : 8
apicid : 6
initial apicid : 6
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 7
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 0
siblings : 8
core id : 7
cpu cores : 8
apicid : 7
initial apicid : 7
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 8
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 0
cpu cores : 8
apicid : 8
initial apicid : 8
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 9
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 1
cpu cores : 8
apicid : 9
initial apicid : 9
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 10
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 2
cpu cores : 8
apicid : 10
initial apicid : 10
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 11
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 3
cpu cores : 8
apicid : 11
initial apicid : 11
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 12
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 4
cpu cores : 8
apicid : 12
initial apicid : 12
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 13
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 5
cpu cores : 8
apicid : 13
initial apicid : 13
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 14
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 6
cpu cores : 8
apicid : 14
initial apicid : 14
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management: processor : 15
vendor_id : GenuineIntel
cpu family : 6
model : 63
model name : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping : 2
microcode : 0x3a
cpu MHz : 2593.993
cache size : 20480 KB
physical id : 1
siblings : 8
core id : 7
cpu cores : 8
apicid : 15
initial apicid : 15
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm epb fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt dtherm arat pln pts
bogomips : 5187.98
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:

命令全部输出

top命令学习

top命令

经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令,但比较奇怪的是能用好它的人却很少,例如top监控视图中内存数值的含义就有不少的曲解。
本文通过一个运行中的WEB服务器的top监控截图,讲述top视图中的各种数据的含义,还包括视图中各进程(任务)的字段的排序。

top进入视图

第一行:
    10:08:45 — 当前系统时间
    10 days, 3:05 — 系统已经运行了10天3小时5分钟(在这期间没有重启过)
    1 users — 当前有1个用户登录系统
    load average: 0.00, 0.00, 0.00 — load average后面的三个数分别是1分钟、5分钟、15分钟的负载情况。

load average数据是每隔5秒钟检查一次活跃的进程数,然后按特定算法计算出的数值。如果这个数除以逻辑CPU的数量,结果高于5的时候就表明系统在超负荷运转了。

    第二行:
    Tasks — 任务(进程),系统现在共有135个进程,其中处于运行中的有1个,134个在休眠(sleep),stoped状态的有0个,zombie状态(僵尸)的有0个。

    第三行:cpu状态
    0.3% us — 用户空间占用CPU的百分比。
    0.0% sy — 内核空间占用CPU的百分比。
    0.0% ni — 改变过优先级的进程占用CPU的百分比
    99.7% id — 空闲CPU百分比
    0.0% wa — IO等待占用CPU的百分比
    0.0% hi — 硬中断(Hardware IRQ)占用CPU的百分比
    0.0% si — 软中断(Software Interrupts)占用CPU的百分比

在这里CPU的使用比率和windows概念不同,如果你不理解用户空间和内核空间,需要充充电了。

第四行:内存状态
    3808060k total — 物理内存总量(4GB)
    3660048k used — 使用中的内存总量(3.6GB)
    148012k free — 空闲内存总量(148M)
    359760k buffers — 缓存的内存量 (359M)

    第五行:swap交换分区
    4184924k total — 交换区总量(4G)
    0k used — 使用的交换区总量(0M)
    4184924k free — 空闲交换区总量(4G)
    2483956k cached — 缓冲的交换区总量(2483M)

第四行中使用中的内存总量(used)指的是现在系统内核控制的内存数,空闲内存总量(free)是内核还未纳入其管控范围的数量。纳入内核管理的内存不见得都在使用中,还包括过去使用过的现在可以被重复利用的内存,内核并不把这些可被重新使用的内存交还到free中去,因此在linux上free内存会越来越少,但不用为此担心。

如果出于习惯去计算可用内存数,这里有个近似的计算公式:第四行的free + 第四行的buffers + 第五行的cached,按这个公式此台服务器的可用内存:148M+259M+2483M = 2990M。

对于内存监控,在top里我们要时刻监控第五行swap交换分区的used,如果这个数值在不断的变化,说明内核在不断进行内存和swap的数据交换,这是真正的内存不够用了。

第六行是空行

第七行以下:各进程(任务)的状态监控
    PID — 进程id
    USER — 进程所有者
    PR — 进程优先级
    NI — nice值。负值表示高优先级,正值表示低优先级
    VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
    RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
    SHR — 共享内存大小,单位kb
    S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
    %CPU — 上次更新到现在的CPU时间占用百分比
    %MEM — 进程使用的物理内存百分比
    TIME+ — 进程使用的CPU时间总计,单位1/100秒
    COMMAND — 进程名称(命令名/命令行)

查看多核cpu的命令

sar查看cpu核数,(待检验)

[machangwei@Mxx01 ~]$ sar #显示了5页内容,前四页的第一列是十分钟就是一行数据,最后一页有cpu平均数据
Linux 3.10.0-957.el7.x86_64 (Msxx01) 2021年11月04日 _x86_64_ (16 CPU) 00时00分01秒 CPU %user %nice %system %iowait %steal %idle
00时10分01秒 all 44.28 0.00 0.37 0.00 0.00 55.34
00时20分01秒 all 44.25 0.00 0.36 0.00 0.00 55.39
00时30分01秒 all 43.93 0.00 0.35 0.00 0.00 55.72
00时40分01秒 all 44.24 0.00 0.36 0.00 0.00 55.40
00时50分01秒 all 43.93 0.00 0.35 0.00 0.00 55.73
01时00分01秒 all 44.25 0.00 0.36 0.00 0.00 55.40
01时10分01秒 all 44.29 0.00 0.40 0.00 0.00 55.31
01时20分01秒 all 43.61 0.00 0.48 0.00 0.00 55.92
01时30分01秒 all 44.16 0.00 0.49 0.00 0.00 55.35
01时40分01秒 all 44.23 0.00 0.51 0.00 0.00 55.26
01时50分01秒 all 43.89 0.00 0.49 0.00 0.00 55.62
02时00分01秒 all 43.87 0.00 0.49 0.00 0.00 55.64
02时10分01秒 all 43.72 0.00 0.59 0.02 0.00 55.67
02时20分01秒 all 43.56 0.00 0.50 0.00 0.00 55.94
02时30分01秒 all 43.91 0.00 0.50 0.00 0.00 55.58
02时40分01秒 all 44.24 0.00 0.56 0.00 0.00 55.20
02时50分02秒 all 43.85 0.00 0.55 0.00 0.00 55.59
03时00分01秒 all 43.92 0.00 0.51 0.00 0.00 55.57
03时10分01秒 all 44.26 0.00 0.53 0.00 0.00 55.20
03时20分01秒 all 43.92 0.00 0.52 0.00 0.00 55.55
03时30分01秒 all 43.94 0.00 0.51 0.00 0.00 55.55
03时40分01秒 all 44.26 0.00 0.51 0.00 0.00 55.23
03时50分01秒 all 43.68 0.00 0.56 0.00 0.00 55.76
04时00分01秒 all 43.85 0.00 0.53 0.00 0.00 55.62
04时10分01秒 all 44.18 0.00 0.59 0.00 0.00 55.23
04时20分01秒 all 44.20 0.00 0.55 0.00 0.00 55.26
04时30分01秒 all 43.87 0.00 0.53 0.00 0.00 55.60
04时40分01秒 all 42.68 0.00 0.78 0.03 0.00 56.51
04时50分02秒 all 43.89 0.00 0.48 0.00 0.00 55.63 ...... 19时20分01秒 CPU %user %nice %system %iowait %steal %idle
19时30分01秒 all 43.88 0.00 0.39 0.00 0.00 55.74
平均时间: all 44.01 0.00 0.48 0.00 0.00 55.51

第一行有系统内核版本,有日期,有应该是cpu架构,有应该是cpu核数

时间从当天零点开始统计,十分钟为一个周期,显示的第一行数据是所有cpu的数据,再往下一行就是每核cpu(这里从0到15,16核)从第一行时间点往后十分钟内的性能数据。all后16行,从0-15的cpu数据

相当于十分钟打印一页,从当天0点到当前时间。0-16核

最后一页数据是平均时间的,也是all加上0-16核

mpstat查看cpu

mpstat -P ALL

[machangwei@xxx01 ~]$ mpstat -h
用法: mpstat [ 选项 ] [ <时间间隔> [ <次数> ] ]
选项:
[ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ]
[ -P { <cpu> [,...] | ON | ALL } ]
[machangwei@xxx01 ~]$ mpstat
Linux 3.10.0-957.el7.x86_64 (xxx01) 2021年11月04日 _x86_64_ (16 CPU) 19时24分06秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
19时24分06秒 all 55.79 0.00 0.31 0.01 0.00 0.14 0.00 0.00 0.00 43.74
[machangwei@xxx01 ~]$ mpstat -u
Linux 3.10.0-957.el7.x86_64 (xxx01) 2021年11月04日 _x86_64_ (16 CPU) 19时24分10秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
19时24分10秒 all 55.79 0.00 0.31 0.01 0.00 0.14 0.00 0.00 0.00 43.74
[machangwei@xxx01 ~]$ mpstat -P ALL
Linux 3.10.0-957.el7.x86_64 (xxx01) 2021年11月04日 _x86_64_ (16 CPU) 19时24分36秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
19时24分36秒 all 55.79 0.00 0.31 0.01 0.00 0.14 0.00 0.00 0.00 43.74
19时24分36秒 0 48.38 0.00 0.45 0.01 0.00 0.64 0.00 0.00 0.00 50.53
19时24分36秒 1 56.85 0.00 0.31 0.01 0.00 0.28 0.00 0.00 0.00 42.56
19时24分36秒 2 56.38 0.00 0.28 0.01 0.00 0.17 0.00 0.00 0.00 43.16
19时24分36秒 3 63.79 0.00 0.21 0.01 0.00 0.09 0.00 0.00 0.00 35.90
19时24分36秒 4 63.71 0.00 0.19 0.01 0.00 0.07 0.00 0.00 0.00 36.02
19时24分36秒 5 37.64 0.00 0.48 0.01 0.00 0.18 0.00 0.00 0.00 61.68
19时24分36秒 6 56.00 0.00 0.34 0.01 0.00 0.14 0.00 0.00 0.00 43.51
19时24分36秒 7 57.98 0.00 0.33 0.01 0.00 0.12 0.00 0.00 0.00 41.56
19时24分36秒 8 59.06 0.00 0.33 0.00 0.00 0.04 0.00 0.00 0.00 40.57
19时24分36秒 9 64.28 0.00 0.26 0.00 0.00 0.03 0.00 0.00 0.00 35.44
19时24分36秒 10 66.02 0.00 0.21 0.00 0.00 0.03 0.00 0.00 0.00 33.75
19时24分36秒 11 55.04 0.00 0.25 0.02 0.00 0.03 0.00 0.00 0.00 44.66
19时24分36秒 12 54.76 0.00 0.32 0.01 0.00 0.11 0.00 0.00 0.00 44.81
19时24分36秒 13 41.46 0.00 0.42 0.04 0.00 0.09 0.00 0.00 0.00 57.98
19时24分36秒 14 54.10 0.00 0.33 0.00 0.00 0.09 0.00 0.00 0.00 45.47
19时24分36秒 15 58.28 0.00 0.31 0.00 0.00 0.10 0.00 0.00 0.00 41.30

实时cpu使用率统计

cpu使用情况可看/proc/stat这个文件,文件内容请参考 https://www.cnblogs.com/no7dw/archive/2011/07/04/2097300.html

参考链接:https://blog.csdn.net/qq_36342854/article/details/116083247

https://www.cnblogs.com/dragonsuc/p/5512797.html

cpu的各种信息查询的更多相关文章

  1. Linux系统CPU相关信息查询

    Linux系统CPU相关信息查询 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.lscpu常用参数介绍 1>.查看帮助信息 [root@node105 ~]# lscpu ...

  2. sql server 运维时CPU,内存,操作系统等信息查询(用sql语句)

    我们只要用到数据库,一般会遇到数据库运维方面的事情,需要我们寻找原因,有很多是关乎处理器(CPU).内存(Memory).磁盘(Disk)以及操作系统的,这时我们就需要查询他们的一些设置和内容,下面讲 ...

  3. linux查询操作系统信息,CPU物理个数,CPU核心数,逻辑CPU数,内存信息查询,硬盘信息查询

    目录 一.前言 二.关于服务器基本配置 2.1 操作系统基本配置查询 2.2 CPU基本配置查询 2.3 内存基本配置查询 2.4 硬盘基本配置查询 一.前言 ​ 当我们接手了一台或者几台服务器的时候 ...

  4. windows平台下 c++获取 系统版本 网卡 内存 CPU 硬盘 显卡信息<转>

    GetsysInfo.h: #ifndef _H_GETSYSINFO #define _H_GETSYSINFO #pragma once #include <afxtempl.h> c ...

  5. PXC集群信息查询

    目录 PXC集群信息查询 pxc流量控制 PXC节点状态 PXC集群状态 节点与集群的相关信息 PXC集群事务相关信息 PXC集群信息查询 show status like "%wsrep% ...

  6. linux 命令查看CPU和内存信息

    几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpu ...

  7. Unix无缓冲文件操作函数、文件信息查询

    问题描述:         Unix无缓冲文件操作函数.文件信息查询 问题解决:        struct stat 结构体信息: 具体代码: 具体源文件:

  8. Android获取cpu和内存信息、网址的代码

      android获取手机cpu并判断是单核还是多核 /** * Gets the number of cores available in this device, across all proce ...

  9. linux查看CPU高速缓存(cache)信息

    一.Linux下查看CPU Cache级数,每级大小 dmesg | grep cache 实例结果如下: 二.查看Cache的关联方式 在 /sys/devices/system/cpu/中查看相应 ...

  10. linux查看CPU和内存信息

    一 先来看看ps命令: 1.查看当前某个时间点的进程:ps命令就是最基本同时也是非常强大的进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程是否结束.进程有没有僵死. 哪些进程占用了 ...

随机推荐

  1. Jetty的https模块

    启用https模块,执行如下命令: java -jar $JETTY_HOME/start.jar --add-modules=https 命令的输出,如下: INFO : https initial ...

  2. c++ 暂停2秒,等待2秒

    std::chrono::milliseconds stopTime(2000); std::this_thread::sleep_for(stopTime);

  3. 鸿蒙HarmonyOS实战-ArkUI组件(Menu)

    一.Menu组件 Menu组件是一种常见的用户界面(UI)控件,用于在移动应用程序中显示可选项列表.它通常由一系列链接或按钮组成,以帮助用户导航和选择所需的操作.Menu组件可以在水平或垂直方向上呈现 ...

  4. sql 语句系列(每个季度的开始日期和结束日期)[八百章之第二十二章]

    前言 基本上统计财务一定会用到. mysql select QUARTER(ADDDATE(y.dy,-1)) QTR, DATE_ADD(y.dy,INTERVAL -3 MONTH) Q_star ...

  5. sql 语句系列(两个日期之间)[八百章之第十七章]

    前言 进入了日期章了. 年月日加减法 分别对原有的日期进行加减法. sql server select DATEADD(DAY,-5,HIREDATE) as hd_mimus_5D, DATEADD ...

  6. 重新点亮linux 命令树————网络管理[十一二]

    前言 简单整理一下网络管理. 正文 网络管理需要掌握: 网络状态查看 网络配置 路由命令 网络故障排除 网络服务管理 常用网络配置文件 网络状态的查看: 1.net-tools ---->1.i ...

  7. StarRocks 集群安装

    当前按照官网上的提供的安装包方式安装,版本是 3.2.2,部署模式为存算一体,安装的操作系统是 Ubuntu 22.04,JDK 版本为 OpenJDK 11,这里选择 3 个节点进行安装,节点的 h ...

  8. opensips使用drouting进行路由

    操作系统 :CentOS 7.6_x64 opensips版本:2.4.9 drouting是Dynamic Routing(动态路由)的缩写,该模块可为特定呼叫选择(基于多个条件)最佳网关.今天整理 ...

  9. 暑期集训 Day7 —— 模拟赛复盘

    ${\color{Green} \mathrm{Problem\ 1 :最优包含 }} $ 发现是 DP,于是开始设计状态:DP[i][j] 表示前一个字符串匹配到位置 i,后一个匹配到 j 的最少修 ...

  10. SpringCloud 应用在 Kubernetes 上的最佳实践 — 线上发布(可监控)

    简介: 本篇是"SpringCloud 应用在 Kubernetes 上的最佳实践"系列文章的第六篇,主要介绍了如何保障生产环境服务稳定,做到随时发布,从而加快业务的迭代和上线速度 ...