[Linux]经典面试题 - 系统管理 - 资源查看

一、操作系统

1.1 uname -a

[root@localhost /]# uname -a
Linux localhost.localdomain 4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

二、进程管理

2.1 ps -l

[root@localhost /]# ps -l
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0    5360    3838  0  80   0 - 59339 -      pts/0    00:00:00 bash
0 R     0    6273    5360  0  80   0 - 63809 -      pts/0    00:00:00 ps

ps -l,仅列出与bash相关的进程,即最上层的父进程是bash,而不是systemd。

字段说明:

  • F:Process Flags 进程标志
    • 4:表示该进程的权限为root;
    • 1:表示此紫禁城仅进行fork而没有实际执行。
  • S:Process Stat 进程状态
    • R:运行中;
    • S:睡眠(idle)状态,可被唤醒(signal)。
    • D:不可被唤醒的睡眠状态,通常是在等待IO
    • T:停止(stop)状态,可能被暂停或者出错。
    • Z:僵尸(zombie)进程,进程已经终止但却无法被移除至内存外。
  • UID:此进程所有者ID
  • PID:此进程的PID号
  • PPID:此进程的父进程PID号
  • C:代表CPU使用率。
  • PRI:Priority 优先级,被CPU所执行的优先级,数值越小约先被执行。
  • TTY:登入的终端位置。
  • TIME:进程实际花费CPU运作的时间。
  • CMD:哪个指令触发的这个进程。

2.2 ps aux

[root@localhost /]# ps aux | head -7
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.1  0.3 245596 14224 ?        Ss   17:06   0:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root           2  0.0  0.0      0     0 ?        S    17:06   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   17:06   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   17:06   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   17:06   0:00 [kworker/0:0H-events_highpri]
root           9  0.0  0.0      0     0 ?        I<   17:06   0:00 [mm_percpu_wq]

ps aux,观察的是系统所有的进程。

字段说明:

  • USER:该进程所有者。
  • PID:该进程标识符。
  • %CPU:该进程使用的CPU占比。
  • %MEM:该进程使用的内存占比。
  • VSZ:该进程占用的虚拟内存量(Kb)。
  • RSS:该进程占用的固定的内存量(kb)。
  • TTY:该进程是在哪个终端机上面运作,若与终端机无关则显示?。
  • STAT:该进程状态,同ps -l。
  • START:该进程被触发启动的时间。
  • TIME:该进程实际使用CPU运作的时间。
  • COMMAND:该进程的实际指令为何?

2.3 ps aux | egrep '(a|b)'

[root@localhost /]# ps aux | egrep '(cron|rsyslog)'
root        1300  0.1  0.3 209440 12136 ?        Ssl  20:11   0:00 /usr/sbin/rsyslogd -n
root        1324  0.0  0.0 233084  2752 ?        Ss   20:11   0:00 /usr/sbin/crond -n
root        2853  0.0  0.0 221928  1152 pts/0    S+   20:12   0:00 grep -E --color=auto (cron|rsyslog)

ps aux | egrep '(cron|rsyslog)',用来查找多个服务。

三、CPU

3.1 lscpu

[root@localhost /]# lscpu
Architecture:        x86_64	#CPU架构
CPU op-mode(s):      32-bit, 64-bit	#操作模式
Byte Order:          Little Endian
CPU(s):              2	#CPU核心个数
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  1	
Socket(s):           2	#线程数
NUMA node(s):        1
Vendor ID:           GenuineIntel
BIOS Vendor ID:      GenuineIntel
CPU family:          6
Model:               60
Model name:          Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
BIOS Model name:     Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz
Stepping:            3
CPU MHz:             3392.148
BogoMIPS:            6784.29
Virtualization:      VT-x	#硬件辅助虚拟化 VT-x
Hypervisor vendor:   VMware
Virtualization type: full	#虚拟化类型:硬件辅助的全虚拟化
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            8192K
NUMA node0 CPU(s):   0,1
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid xsaveopt arat md_clear flush_l1d arch_capabilities	#指令集

四、内存

4.1 free -mh

[root@localhost /]# free -mh
              total        used        free      shared  buff/cache   available
Mem:          3.6Gi       998Mi       1.8Gi        16Mi       821Mi       2.4Gi
Swap:         8.0Gi          0B       8.0Gi

free -mh,查看内存占用。

字段说明:

  • buff/cache:在这里,buff指的是Buffer cache;cache指的是Page cache。

五、硬盘

5.1 df-hT

[root@localhost /]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs               tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs               tmpfs     1.9G  9.7M  1.9G   1% /run
tmpfs               tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/cl-root xfs        91G  5.5G   86G   6% /
/dev/sda1           ext4      976M  241M  669M  27% /boot
tmpfs               tmpfs     371M   28K  371M   1% /run/user/0
/dev/sr0            iso9660   1.6G  1.6G     0 100% /run/media/root/CentOS-8-2-2004-x86_64-dvd

5.2 lsblk

[root@localhost /]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  100G  0 disk 
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   99G  0 part 
  ├─cl-root 253:0    0   91G  0 lvm  /
  └─cl-swap 253:1    0    8G  0 lvm  [SWAP]
sr0          11:0    1  1.6G  0 rom  /run/media/root/CentOS-8-2-2004-x86_64-dvd

5.3 fdisk -l

[root@localhost /]# fdisk -l
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x58f49df1

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 209715199 207616000  99G 8e Linux LVM


Disk /dev/mapper/cl-root: 91 GiB, 97706311680 bytes, 190832640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/cl-swap: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

5.4 parted

[root@localhost /]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  ext4         boot
 2      1075MB  107GB   106GB   primary               lvm

六、网络

6.1 ip addr

[root@localhost /]# ip addr
1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <broadcast,multicast,up,lower_up> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:dc:c2:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.100/24 brd 192.168.9.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::5cf2:974e:5067:d5ab/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <no-carrier,broadcast,multicast,up> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:d3:07:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <broadcast,multicast> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:d3:07:24 brd ff:ff:ff:ff:ff:ff

6.2 ifconfig

[root@localhost /]# ifconfig
ens33: flags=4163<up,broadcast,running,multicast>  mtu 1500
        inet 192.168.9.100  netmask 255.255.255.0  broadcast 192.168.9.255
        inet6 fe80::5cf2:974e:5067:d5ab  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:dc:c2:3e  txqueuelen 1000  (Ethernet)
        RX packets 171  bytes 30453 (29.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 188  bytes 18577 (18.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<up,loopback,running>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 24  bytes 1976 (1.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 24  bytes 1976 (1.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<up,broadcast,multicast>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:d3:07:24  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

posted @ 2021-06-25 20:32  SkyBiuBiu  阅读(160)  评论(0编辑  收藏  举报