在Linux上查看CPU,内存等信息

直接查看CPU信息

cat /proc/cpuinfo

显示结果:

[centos@www ~]$ cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3300.201
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 0
cpu cores   : 4
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
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       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3300.402
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 1
cpu cores   : 4
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
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       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3151.153
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 2
cpu cores   : 4
apicid      : 4
initial apicid  : 4
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
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       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3300.402
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 3
cpu cores   : 4
apicid      : 6
initial apicid  : 6
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 4
vendor_id   : GenuineIntel
cpu family  : 6
model       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3467.376
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 0
cpu cores   : 4
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 5
vendor_id   : GenuineIntel
cpu family  : 6
model       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3379.962
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 1
cpu cores   : 4
apicid      : 3
initial apicid  : 3
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 6
vendor_id   : GenuineIntel
cpu family  : 6
model       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3247.229
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 2
cpu cores   : 4
apicid      : 5
initial apicid  : 5
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 7
vendor_id   : GenuineIntel
cpu family  : 6
model       : 60
model name  : Intel(R) Xeon(R) CPU E3-1230 v3 @ 3.30GHz
stepping    : 3
microcode   : 0x25
cpu MHz     : 3300.604
cache size  : 8192 KB
physical id : 0
siblings    : 8
core id     : 3
cpu cores   : 4
apicid      : 7
initial apicid  : 7
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
bogomips    : 6585.03
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

从上面的结果中可以看到该服务器有8个CPU,第个CPU有4个核心Cores

查看CPU处理器个数及核心数,可以使用grep过滤

[centos@www ~]$ cat /proc/cpuinfo | grep processor
processor   : 0
processor   : 1
processor   : 2
processor   : 3
processor   : 4
processor   : 5
processor   : 6
processor   : 7
[centos@www ~]$ cat /proc/cpuinfo | grep processor | wc -l
8
[centos@www ~]$ cat /proc/cpuinfo | grep cores
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
cpu cores   : 4
[centos@www ~]$ 

我们可以看到总共有8个CPU处理器,每个CPU含4个核心,所以总共是32核处理器。

查看内存信息

[centos@www ~]$ cat /proc/meminfo
MemTotal:       16194048 kB
MemFree:         5333804 kB
MemAvailable:   14105500 kB
Buffers:            2288 kB
Cached:          9013612 kB
SwapCached:            0 kB
Active:          3612836 kB
Inactive:        6636128 kB
Active(anon):    1233620 kB
Inactive(anon):    86700 kB
Active(file):    2379216 kB
Inactive(file):  6549428 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       8191996 kB
SwapFree:        8191996 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:       1233684 kB
Mapped:           211588 kB
Shmem:             87256 kB
Slab:             260368 kB
SReclaimable:     179268 kB
SUnreclaim:        81100 kB
KernelStack:        9728 kB
PageTables:        47988 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    16289020 kB
Committed_AS:    4823120 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      103164 kB
VmallocChunk:   34359537660 kB
HardwareCorrupted:     0 kB
AnonHugePages:    798720 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      207924 kB
DirectMap2M:     4962304 kB
DirectMap1G:    11534336 kB

使用free查看内存使用情况

[centos@www ~]$ free
              total        used        free      shared  buff/cache   available
Mem:       16194048     1584736     5332956       87256     9276356    14104664
Swap:       8191996           0     8191996
[centos@www ~]$ free -m # 这个是以M为单位显示
              total        used        free      shared  buff/cache   available
Mem:          15814        1548        5207          85        9058       13773
Swap:          7999           0        7999
[centos@www ~]$ free -h # 以人类习惯的方式显示
              total        used        free      shared  buff/cache   available
Mem:            15G        1.5G        5.1G         85M        8.8G         13G
Swap:          7.8G          0B        7.8G
[centos@www ~]$ 

可以看到总共15G,空闲5.1G。

查看CPU和内存使用情况(top),进程运行情况

top - 09:43:47 up 9 days, 19:33,  1 user,  load average: 0.00, 0.03, 0.25
Tasks: 268 total,   1 running, 267 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.5 us,  1.8 sy,  0.0 ni, 96.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16194048 total,  5332024 free,  1585640 used,  9276384 buff/cache
KiB Swap:  8191996 total,  8191996 free,        0 used. 14103920 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                              
  791 polkitd   20   0  649824  20876   5388 S   6.3  0.1 806:00.02 polkitd                                                              
  816 dbus      20   0   70136   4116   1912 S   2.0  0.0 277:23.16 dbus-daemon                                                          
  779 root      20   0  399012   6920   3264 S   1.7  0.0 199:33.26 accounts-daemon                                                      
 2281 centos    20   0  611424   7156   5208 S   1.0  0.0  83:13.95 gsd-account                                                          
 1728 mysql     20   0 2240652 453056   9428 S   0.3  2.8   9:46.71 mysqld                                                               
    1 root      20   0  194068   7256   4180 S   0.0  0.0   0:40.82 systemd                                                              
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.37 kthreadd                                                             
    3 root      20   0       0      0      0 S   0.0  0.0   0:02.36 ksoftirqd/0                                                          
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H                                                         
    7 root      rt   0       0      0      0 S   0.0  0.0   0:00.07 migration/0                                                          
    8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh                                                               
    9 root      20   0       0      0      0 S   0.0  0.0   7:19.47 rcu_sched                                                            
   10 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 lru-add-drain                                                        
   11 root      rt   0       0      0      0 S   0.0  0.0   0:01.88 watchdog/0                                                           
   12 root      rt   0       0      0      0 S   0.0  0.0   0:02.00 watchdog/1                                                           
   13 root      rt   0       0      0      0 S   0.0  0.0   0:00.06 migration/1                                                          
   14 root      20   0       0      0      0 S   0.0  0.0   0:02.28 ksoftirqd/1                                                          
   16 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/1:0H                                                         
   17 root      rt   0       0      0      0 S   0.0  0.0   0:01.55 watchdog/2                                                           
   18 root      rt   0       0      0      0 S   0.0  0.0   0:00.02 migration/2                                                          
   19 root      20   0       0      0      0 S   0.0  0.0   0:02.37 ksoftirqd/2                                                          
   21 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/2:0H                                                         
   22 root      rt   0       0      0      0 S   0.0  0.0   0:01.69 watchdog/3                                                           
   23 root      rt   0       0      0      0 S   0.0  0.0   0:00.05 migration/3                                                          
   24 root      20   0       0      0      0 S   0.0  0.0   0:02.35 ksoftirqd/3                                                          
   26 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/3:0H                                                         
   27 root      rt   0       0      0      0 S   0.0  0.0   0:02.33 watchdog/4                                                           
   28 root      rt   0       0      0      0 S   0.0  0.0   0:22.43 migration/4                                                          
   29 root      20   0       0      0      0 S   0.0  0.0   0:07.87 ksoftirqd/4                                                          
   31 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/4:0H                                                         
   32 root      rt   0       0      0      0 S   0.0  0.0   0:02.43 watchdog/5                                                           
   33 root      rt   0       0      0      0 S   0.0  0.0   0:24.16 migration/5                                                          
   34 root      20   0       0      0      0 S   0.0  0.0   0:07.39 ksoftirqd/5                                                          
   36 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/5:0H        

使用这个命令,会一直在终端上动态更新当前的CPU,内存使用情况。通过输入 q可退出。

top命令结果讲解

进程列表部分:
  PID:进程的ID
  USER:进程所有者
  PR:进程的优先级别,越小越优先被执行
  NInice:值
  VIRT:进程占用的虚拟内存
  RES:进程占用的物理内存
  SHR:进程使用的共享内存
  S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数
  %CPU:进程占用CPU的使用率
  %MEM:进程使用的物理内存和总内存的百分比
  TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。
  COMMAND:进程启动命令名称
系统信息栏:  
  第一行(top):
    系统当前时刻;
    系统启动后到现在的运作时间;
    当前登录到系统的用户,更确切的说是登录到用户的终端数;
    当前系统负载的平均值,三个值分别为1分钟前、5分钟前、15分钟前进程的平均数;
  第二行(Tasks):
    total:当前系统进程总数;
    running:当前运行中的进程数;
    sleeping:当前处于睡眠状态中的进程数;
    stopped:被停止的系统进程数;
    zombie:僵尸进程数;
  第三行(Cpus):
    分别表示了 CPU 当前的使用率;
  第四行(Mem):
    分别表示了内存总量、当前使用量、空闲内存量、以及缓冲使用中的内存量;
  第五行(Swap):
    表示类别同第四行(Mem),但此处反映着交换分区(Swap)的使用情况。