前端开发入门到精通的在线学习网站

网站首页 > 资源文章 正文

名企高频考点指令篇-Linux查看CPU内存和系统版本

qiguaw 2024-09-06 21:08:05 资源文章 20 ℃ 0 评论

名企高频考点指令篇-Linux查看CPU内存和系统版本

全平台账号同名

0. 概述

在我们面试各大公司的时候,关于Linux往往最容易被问到的问题之一就是Linux指令,而其中,对系统软硬件参数的获取,又是相对比较容易被问到的。因为对这些参数的了解,最能直观反映应聘者对Linux环境是否熟悉。我们结合海量面经,提取出四个最容易被问到的Linux查看软硬件参数的命令,供大家参考。

  • 如何查看Linux硬盘使用情况
  • 如何查看Linux CPU使用情况
  • 如何查看Linux 内存使用情况
  • 如何查看Linux 查看系统版本

我们今天搞定后3个吧!

1.查看CPU信息

查看CPU信息的方式很多,我们这里分两种情况来处理

1.1 查看CPU基本硬件信息
[whb@VM_0_12_centos test]$ cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 79
model name  : Intel(R) Xeon(R) CPU E5-26xx v4
stepping    : 1
microcode   : 0x1
cpu MHz     : 2399.996
cache size  : 4096 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
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 mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl 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 3dnowprefetch bmi1 avx2 bmi2 rdseed adx xsaveopt
bogomips    : 4799.99
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:
1.2 查看CPU使用状态信息, top && dstat
#方法一
[whb@VM_0_12_centos test]$ top #输入top查看CPU使用情况,可以输入1,查看多核CPU使用情况
asks:  74 total,   2 running,  72 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1882892 total,   148092 free,   403032 used,  1331768 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  1274708 avail Mem 
?
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 3677 root      20   0  162348  10684   1364 S  1.1  0.6  91:47.96 barad_agent
 3678 root      20   0  611460  13444   1484 S  1.1  0.7 462:59.39 barad_agent
    1 root      20   0   51644   3056   1840 S  0.0  0.2  12:14.31 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.66 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   2:00.04 ksoftirqd/0
#方法二
[whb@VM_0_12_centos test]$ dstat -c #不存在,centos上可使用 yum -y install dstat 安装
----total-cpu-usage----
usr sys idl wai hiq siq
 25   0  74   0   0   0
  1   0  99   0   0   0

2.查看内存信息

查看内存信息的方式也很多,我们这里也分两种情况来处理

2.1 查看内存基本容量信息
[whb@VM_0_12_centos test]$ cat /proc/meminfo 
MemTotal:        1882892 kB
MemFree:          147760 kB
MemAvailable:    1275048 kB
Buffers:          165600 kB
Cached:           878652 kB
SwapCached:            0 kB
Active:           891404 kB
...
2.2 查看内存运行空间信息
[whb@VM_0_12_centos test]$ free 
              total        used        free      shared  buff/cache   available
Mem:        1882892      403124      146836         544     1332932     1274648
Swap:             0           0           0
[whb@VM_0_12_centos test]$ free -k #安装KB为单位显示
              total        used        free      shared  buff/cache   available
Mem:        1882892      402988      146964         544     1332940     1274788
Swap:             0           0           0
[whb@VM_0_12_centos test]$ free -m #安装MB为单位进行显示
              total        used        free      shared  buff/cache   available
Mem:           1838         393         143           0        1301        1244
Swap:             0           0           0

3.查看Linux 查看系统版本

[whb@VM_0_12_centos test]$ uname -a
Linux VM_0_12_centos 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[whb@VM_0_12_centos test]$ cat /etc/redhat-release  #如果是centos机器,可以直接查看更细致版本
CentOS Linux release 7.5.1804 (Core) 

4. 总结

  • 这块整体比较简单,后面再面试的时候,要准备哦


作者:王海斌

审稿:王海斌

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表