Linux下的/proc目录常用命令

proc被称为虚拟文件系统,它是一个控制中心,可以通过更改其中某些文件改变内核运行状态,它也是内核提供给我们的查询中心,用户可以通过它查看系统硬件及当前运行的进程信息。

1. 平均负载 loadavg

前三个数字是1、5、15分钟内的平均进程数。

后面两个,一个的分子是正在运行的进程数,分母是进程总数;另一个是最近运行的进程ID号。

wanglei@wanglei-PC:~$ cat /proc/loadavg 
0.17 0.21 0.18 1/1047 23919

2. 当前内存使用信息 meminfo

wanglei@wanglei-PC:~$ cat /proc/meminfo
/ $ cat /proc/meminfo
MemTotal:         877368 kB  :所有可用RAM大小(即物理内存减去一些预留位和内核的二进制代码大小)(HighTotal + LowTotal),系统从加电开始到引导完成,BIOS等要保留一些内存,内核要保留一些内存,最后剩下可供系统支配的内存就是MemTotal。这个值在系统运行期间一般是固定不变的。
MemFree:           22516 kB  :LowFree与HighFree的总和,被系统留着未使用的内存,MemFree是说的系统层面
MemAvailable:     470244 kB  :应用程序可用内存数。系统中有些内存虽然已被使用但是可以回收的,比如cache/buffer、slab都有一部分可以回收,所以MemFree不能代表全部可用的内存,这部分可回收的内存加上MemFree才是系统可用的内存,即:MemAvailable≈MemFree+Buffers+Cached,它是内核使用特定的算法计算出来的,是一个估计,MemAvailable是说的应用程序层面
Buffers:            1772 kB  :用来给文件做缓冲大小
Cached:           459224 kB  :被高速缓冲存储器(cache memory)用的内存的大小(等于 diskcache minus SwapCache )
SwapCached:           16 kB  :被高速缓冲存储器(cache memory)用的交换空间的大小,已经被交换出来的内存,但仍然被存放在swapfile中。用来在需要的时候很快的被替换而不需要再次打开I/O端口
Active:           333148 kB  :在活跃使用中的缓冲或高速缓冲存储器页面文件的大小,除非非常必要否则不会被移作他用. (Active(anon) + Active(file))
Inactive:         330384 kB  :在不经常使用中的缓冲或高速缓冲存储器页面文件的大小,可能被用于其他途径. (Inactive(anon) + Inactive(file))
Active(anon):     104368 kB  :活跃的与文件无关的内存(比如进程的堆栈,用malloc申请的内存)(anonymous pages),anonymous pages在发生换页时,是对交换区进行读/写操作
Inactive(anon):   104508 kB  :非活跃的与文件无关的内存(比如进程的堆栈,用malloc申请的内存)
Active(file):     228780 kB  :活跃的与文件关联的内存(比如程序文件、数据文件所对应的内存页)(file-backed pages) File-backed pages在发生换页(page-in或page-out)时,是从它对应的文件读入或写出
Inactive(file):   225876 kB  :非活跃的与文件关联的内存(比如程序文件、数据文件所对应的内存页)
Unevictable:        6708 kB  :
Mlocked:            1428 kB  :
HighTotal:        261888 kB  :高位内存总大小(Highmem是指所有内存高于860MB的物理内存,Highmem区域供用户程序使用,或用于页面缓存。该区域不是直接映射到内核空间。内核必须使用不同的手法使用该段内存)
HighFree:           5680 kB  :未被使用的高位内存大小
LowTotal:         615480 kB  :低位内存总大小,低位可以达到高位内存一样的作用,而且它还能够被内核用来记录一些自己的数据结构
LowFree:           16836 kB  :未被使用的低位大小
SwapTotal:        614396 kB  :交换空间的总大小
SwapFree:         611044 kB  :未被使用交换空间的大小
Dirty:                40 kB  :等待被写回到磁盘的内存大小
Writeback:             0 kB  :正在被写回到磁盘的内存大小
AnonPages:        209224 kB  :未映射页的内存大小
Mapped:           280668 kB  :设备和文件等映射的大小
Shmem:              1084 kB  :
Slab:              59840 kB  :内核数据结构缓存的大小,可以减少申请和释放内存带来的消耗
SReclaimable:      34196 kB  :可收回Slab的大小
SUnreclaim:        25644 kB  :不可收回Slab的大小(SUnreclaim+SReclaimable=Slab)
KernelStack:        7504 kB  :常驻内存,每一个用户线程都会分配一个kernel stack(内核栈)
PageTables:        15508 kB  :管理内存分页页面的索引表的大小
NFS_Unstable:          0 kB  :不稳定页表的大小
Bounce:                0 kB  :
WritebackTmp:          0 kB  :
CommitLimit:     1053080 kB  :根据超额分配比率('vm.overcommit_ratio'),这是当前在系统上分配可用的内存总量,这个限制只是在模式2('vm.overcommit_memory')时启用。CommitLimit用以下公式计算:CommitLimit ='vm.overcommit_ratio'*物理内存)+交换例如,在具有1G物理RAM和7G swap的系统上,当`vm.overcommit_ratio` = 30时 CommitLimit =7.3G
Committed_AS:   16368536 kB  :目前在系统上分配的内存量。是所有进程申请的内存的总和,即时所有申请的内存没有被完全使用,例如一个进程申请了1G内存,仅仅使用了300M,但是这1G内存的申请已经被 "committed"给了VM虚拟机,进程可以在任何时间使用。如果限制在模式2('vm.overcommit_memory')时启用,分配超出CommitLimit内存将不被允许
VmallocTotal:     245760 kB  :可以vmalloc虚拟内存大小
VmallocUsed:           0 kB  :vmalloc已使用的虚拟内存大小
VmallocChunk:          0 kB  :最大的连续未被使用的vmalloc区域
Percpu:            11264 kB
HardwareCorrupted:     0 kB
AnonHugePages:    811008 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0  //大页面的分配
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      381816 kB
DirectMap2M:     7886848 kB
DirectMap1G:           0 kB

3. 磁盘I/O统计信息列表 diskstats

wanglei@wanglei-PC:~$ cat /proc/diskstats 
   7       0 loop0 55 0 2148 501 0 0 0 0 0 64 452 0 0 0 0
   7       1 loop1 164 0 2356 3312 0 0 0 0 0 96 3120 0 0 0 0
   7       2 loop2 12028 0 26084 11036 0 0 0 0 0 956 8436 0 0 0 0
   7       3 loop3 4 0 8 0 0 0 0 0 0 4 0 0 0 0 0
   7       4 loop4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       5 loop5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       6 loop6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       7 loop7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   8       0 sda 84938 40291 8395078 895059 277226 344512 22236441 2028040 0 398544 2643664 0 0 0 0
   8       1 sda1 105 1022 6600 4831 1 0 1 0 0 196 4740 0 0 0 0
   8       2 sda2 113 21 16026 1186 14 13 216 714 0 252 1764 0 0 0 0
   8       3 sda3 84212 38927 8344226 880283 237167 318925 21802920 1824557 0 389188 2466740 0 0 0 0
   8       4 sda4 81 0 6400 1008 0 0 0 0 0 132 940 0 0 0 0
   8       5 sda5 64 90 5186 1455 1 0 8 51 0 136 1444 0 0 0 0
   8       6 sda6 264 231 11880 5317 28588 25574 433296 51542 0 3296 38256 0 0 0 0
  11       0 sr0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1. 设备号 (major number )

  2. 编号 (minor mumber)

  3. 设备 (device name )

  4. 读完成次数(reads completed successfully)

  5. 合并完成次数(reads merged)

  6. 读扇区次数 (sectors read )

  7. 读操作花费毫秒数 (time spent reading (ms))

  8. 写完成次数 (writes completed)

  9. 合并写完成次数 (writes merged)

  10. 写扇区次数 (sectors written)

  11. 写操作花费的毫秒数 (time spent writing (ms))

  12. 正在处理的输入/输出请求数 (I/Os currently in progress)

  13. 输入/输出操作花费的毫秒数 (time spent doing I/Os (ms))

  14. 输入/输出操作花费的加权毫秒数(weighted time spent doing I/Os (ms))

  15. -18.不知道

4. 网络流入流出统计信息 net/dev

wanglei@wanglei-PC:~$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:  331497    6083    0    0    0     0          0         0   331497    6083    0    0    0     0       0          0
enp1s0: 388915855  470560    0    0    0     0          0      5467 53193373  359870    0    0    0     0       0          0

Receive(输入字节数)

Transmit(输出字节数)

5. 支持的文件系统 filesystems

wanglei@wanglei-PC:~$ cat /proc/filesystems
nodev	sysfs
nodev	tmpfs
nodev	bdev
nodev	proc
nodev	cgroup
nodev	cgroup2
nodev	cpuset
nodev	devtmpfs
nodev	configfs
nodev	debugfs
nodev	tracefs
nodev	securityfs
nodev	sockfs
nodev	bpf
nodev	pipefs
nodev	ramfs
nodev	hugetlbfs
nodev	devpts
	ext3
	ext2
	ext4
	squashfs
	vfat
nodev	ecryptfs
	fuseblk
nodev	fuse
nodev	fusectl
nodev	efivarfs
nodev	mqueue
nodev	pstore
nodev	autofs

6. CPU的详细信息 cpuinfo

wanglei@wanglei-PC:~$ cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 158
model name	: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
stepping	: 10
microcode	: 0xea
cpu MHz		: 4369.113
cache size	: 12288 KB
physical id	: 0
siblings	: 12
core id		: 0
cpu cores	: 6
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
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 art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf 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 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit
bogomips	: 6399.96
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:


省略了剩下的11个cpu

processor:系统中逻辑处理核的编号。对于单核处理器,则课认为是其CPU编号,对于多核处理器则可以是物理核、或者使用超线程技术虚拟的逻辑核
vendor_id:CPU制造商
cpu family:CPU产品系列代号
model:CPU属于其系列中的哪一代的代号
model name:CPU属于的名字及其编号、标称主频
stepping:CPU属于制作更新版本
cpu MHz:CPU的实际使用主频
cache size:CPU二级缓存大小
physical id:单个CPU的标号
siblings:单个CPU逻辑物理核数
core id:当前物理核在其所处CPU中的编号,这个编号不一定连续
cpu cores :该逻辑核所处CPU的物理核数
apicid :用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续
fpu:是否具有浮点运算单元(Floating Point Unit)
fpu_exception :是否支持浮点计算异常
cpuid level :执行cpuid指令前,eax寄存器中的值,根据不同的值cpuid指令会返回不同的内容
wp:表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)
flags :当前CPU支持的功能
bogomips:在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second)
clflush size:每次刷新缓存的大小单位
cache_alignment:缓存地址对齐单位
address sizes:可访问地址空间位数
power management:对能源管理的支持

7. 启动时传递至内核的启动参数 cmdline

wanglei@wanglei-PC:~$ cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-5.4.18-35-generic root=UUID=27c0f201-f84a-4c90-9948-a784b15dd58c ro quiet splash resume=UUID=23ce9575-3076-4d8c-9357-f3512362942e audit=0 security=none

8. 系统当前挂载的文件系统 mounts

wanglei@wanglei-PC:~$ cat /proc/mounts
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,noexec,relatime,size=3987432k,nr_inodes=996858,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=802660k,mode=755 0 0
/dev/sda3 / ext4 rw,relatime 0 0
none /sys/kernel/security securityfs rw,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup2 /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
none /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/rdma cgroup rw,nosuid,nodev,noexec,relatime,rdma 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=20033 0 0
mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0
tracefs /sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0
fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0
configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0
/dev/loop0 /snap/core/11798 squashfs ro,nodev,relatime 0 0
/dev/loop2 /snap/core/11993 squashfs ro,nodev,relatime 0 0
/dev/loop1 /snap/electronic-wechat/7 squashfs ro,nodev,relatime 0 0
/dev/sda2 /boot ext4 rw,relatime 0 0
/dev/sda1 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0
/dev/sda5 /data ext4 rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=802660k,mode=700,uid=1000,gid=1000 0 0
gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0

9. 系统运行时间 uptime

wanglei@wanglei-PC:~$ cat /proc/uptime 
30835.25 365526.76

第一列输出的是,系统启动到现在的时间(以秒为单位)
第二列输出的是,系统空闲的时间(以秒为单位)

10. 当前运行的内核版本号等信息 version

wanglei@wanglei-PC:~$ cat /proc/version
Linux version 5.4.18-35-generic (buildd@localhost) (gcc version 9.3.0 (Ubuntu 9.3.0-10kylin2)) #21-KYLINOS SMP Tue Jul 20 13:33:58 UTC 2021

11. 查看中断信息 interrupts

列出当前所以系统注册的中断,记录中断号,中断发生次数,中断设备名称

从左至右:中断号 中断次数 中断设备名称

cat /proc/interrupts
        CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       CPU6       CPU7       CPU8       CPU9       CPU10      CPU11 
        0:          7          0          0          0          0          0          0          0          0          0          0          0  IR-IO-APIC    2-edge      timer
        8:          0          0          0          0          0          1          0          0          0          0          0          0  IR-IO-APIC    8-edge      rtc0
        9:          0          5          0          0          0          0          0          0          0          0          0          0  IR-IO-APIC    9-fasteoi   acpi
        16:          0          0          0          0          0          0          0          0          0          0          0          0  IR-IO-APIC   16-fasteoi   i801_smbus
        120:          0          0          0          0          0          0          0          0          0          0          0          0  DMAR-MSI    0-edge      dmar0
        121:          0          0          0          0          0          0          0          0          0          0          0          0  DMAR-MSI    1-edge      dmar1
        122:          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI 458752-edge      PCIe PME, aerdrv, pcie-dpc
        123:          0          0          0          0          0          0          0          0          0          0          0          0  IR-PCI-MSI 468992-edge      PCIe PME, aerdrv, pcie-dpc
        124:          0          0          0          0     226437          0          0          0          0          0          0          0  IR-PCI-MSI 327680-edge      xhci_hcd
        125:          0          0          0          0          0          0     292650          0          0          0          0          0  IR-PCI-MSI 376832-edge      ahci[0000:00:17.0]
        126:          0          0          0          0          0          0          0    1096768          0          0          0          0  IR-PCI-MSI 32768-edge      i915
        127:          0          0          0          0          0          0          0          0          0         34          0          0  IR-PCI-MSI 360448-edge      mei_me
        128:          0          0          0          0          0          0          0          0          0          0          0     365694  IR-PCI-MSI 524288-edge      enp1s0
        129:          0          0          0          0          0          0          0          0          0          0        717          0  IR-PCI-MSI 514048-edge      snd_hda_intel:card0
        NMI:         23         22         22         22         23         22         23         23         21         21         22         23   Non-maskable interrupts
        LOC:    1440946    1395999    1448517    1424556    1491546    1401173    1447048    1767996    1436419    1406391    1350789    1355120   Local timer interrupts
        SPU:          0          0          0          0          0          0          0          0          0          0          0          0   Spurious interrupts
        PMI:         23         22         22         22         23         22         23         23         21         21         22         23   Performance monitoring interrupts
        IWI:          1          1          1          4          3          0          3     122243          1          1          1          2   IRQ work interrupts
        RTR:          0          0          0          0          0          0          0          0          0          0          0          0   APIC ICR read retries
        RES:     158718      53658      25775      17263      15113      13046      12487      14999      10982      10532      10749      13006   Rescheduling interrupts
        CAL:      88685      88534      85685      82815      86503      86028      85463      91799      76953      80662      88195      86127   Function call interrupts
        TLB:     139014     131953     134452     125712     130481     131952     128183     138051     119873     124785     133004     133951   TLB shootdowns
        TRM:          0          0          0          0          0          0          0          0          0          0          0          0   Thermal event interrupts
        THR:          0          0          0          0          0          0          0          0          0          0          0          0   Threshold APIC interrupts
        DFR:          0          0          0          0          0          0          0          0          0          0          0          0   Deferred Error APIC interrupts
        MCE:          0          0          0          0          0          0          0          0          0          0          0          0   Machine check exceptions
        MCP:         61         62         62         62         62         62         62         62         62         62         62         62   Machine check polls
        HYP:          0          0          0          0          0          0          0          0          0          0          0          0   Hypervisor callback interrupts
        HRE:          0          0          0          0          0          0          0          0          0          0          0          0   Hyper-V reenlightenment interrupts
        HVS:          0          0          0          0          0          0          0          0          0          0          0          0   Hyper-V stimer0 interrupts
        ERR:          0
        MIS:          0
        PIN:          0          0          0          0          0          0          0          0          0          0          0          0   Posted-interrupt notification event
        NPI:          0          0          0          0          0          0          0          0          0          0          0          0   Nested posted-interrupt event
        PIW:          0          0          0          0          0          0          0          0          0          0          0          0   Posted-interrupt wakeup event

你可能感兴趣的:(linux,运维,服务器)