proc 文件系统

1、简介

proc 是一个虚拟文件系统,通常作为进程信息的伪文件系统,里面没有真正的文件,但是却包含系统运行信息(系统内存、设备mount、硬件配置)。proc 文件系统可以认为是内核的控制和信息中心,许多的系统应用程序只是简单的对这个文件进行读写使用,例如lsmod 等效于 cat /proc/modules,lspci 等同于 cat /proc/pci ,更改proc目录下的文件,可读写正在运行的系统kernel 相关参数。

/proc/下文件较为特别,除kcore、mtrr、self极少数文件外,这些文件大小为0。

 大部分/proc 下的文件都是只读的,修改部分文件可以改变内核变量,从而达到不重新编译内核、不重启设备情况下修改内核。

procinfo 命令可以将proc文件系统信息显示出来

[root@localhost proc]# ls -lah
total 4.0K
dr-xr-xr-x 626 root root 0 Feb 7 17:54 .
dr-xr-xr-x. 20 root root 4.0K Feb 7 17:56 ..
dr-xr-xr-x 9 root root 0 Feb 7 17:54 1
dr-xr-xr-x 9 root root 0 Feb 7 19:27 10
dr-xr-xr-x 9 root root 0 Feb 7 19:27 100
dr-xr-xr-x 9 root root 0 Feb 7 19:27 1001
dr-xr-xr-x 9 root root 0 Feb 7 19:27 101
dr-xr-xr-x 9 root root 0 Feb 7 19:27 999
dr-xr-xr-x 2 root root 0 Feb 8 01:18 acpi
-r--r--r-- 1 root root 0 Feb 8 01:18 buddyinfo
dr-xr-xr-x 4 root root 0 Feb 8 01:18 bus
-r--r--r-- 1 root root 0 Feb 8 01:18 cgroups
-r--r--r-- 1 root root 0 Feb 8 01:18 cmdline
-r--r--r-- 1 root root 0 Feb 8 01:18 consoles
-r--r--r-- 1 root root 0 Feb 8 01:18 cpuinfo
-r--r--r-- 1 root root 0 Feb 8 01:18 crypto
-r--r--r-- 1 root root 0 Feb 8 01:18 devices
-r--r--r-- 1 root root 0 Feb 8 01:18 diskstats
-r--r--r-- 1 root root 0 Feb 8 01:18 dma
dr-xr-xr-x 2 root root 0 Feb 8 01:18 driver
-r--r--r-- 1 root root 0 Feb 8 01:18 execdomains
-r--r--r-- 1 root root 0 Feb 8 01:18 fb
-r--r--r-- 1 root root 0 Feb 8 01:18 filesystems
dr-xr-xr-x 4 root root 0 Feb 8 01:18 fs
-r--r--r-- 1 root root 0 Feb 8 01:18 interrupts
-r--r--r-- 1 root root 0 Feb 8 01:18 iomem
-r--r--r-- 1 root root 0 Feb 8 01:18 ioports
dr-xr-xr-x 3 root root 0 Feb 8 01:18 ipmi
dr-xr-xr-x 53 root root 0 Feb 8 01:18 irq
-r--r--r-- 1 root root 0 Feb 8 01:18 kallsyms
-r-------- 1 root root 128T Feb 8 01:18 kcore
-r--r--r-- 1 root root 0 Feb 8 01:18 keys
-r--r--r-- 1 root root 0 Feb 8 01:18 key-users
-r-------- 1 root root 0 Feb 8 01:18 kmsg
-r-------- 1 root root 0 Feb 8 01:18 kpagecount
-r-------- 1 root root 0 Feb 8 01:18 kpageflags
-r--r--r-- 1 root root 0 Feb 8 01:18 loadavg
-r--r--r-- 1 root root 0 Feb 8 01:18 locks
-r--r--r-- 1 root root 0 Feb 8 01:18 mdstat
-r--r--r-- 1 root root 0 Feb 8 01:18 meminfo
-r--r--r-- 1 root root 0 Feb 8 01:18 misc
-r--r--r-- 1 root root 0 Feb 8 01:18 modules
lrwxrwxrwx 1 root root 11 Feb 8 01:18 mounts -> self/mounts
-rw-r--r-- 1 root root 0 Feb 7 17:55 mtrr
lrwxrwxrwx 1 root root 8 Feb 8 01:18 net -> self/net
-r--r--r-- 1 root root 0 Feb 8 01:18 pagetypeinfo
-r--r--r-- 1 root root 0 Feb 8 01:18 partitions
-r--r--r-- 1 root root 0 Feb 8 01:18 sched_debug
-r--r--r-- 1 root root 0 Feb 8 01:18 schedstat
dr-xr-xr-x 3 root root 0 Feb 8 01:18 scsi
lrwxrwxrwx 1 root root 0 Feb 7 17:54 self -> 16779
-r-------- 1 root root 0 Feb 8 01:18 slabinfo
-r--r--r-- 1 root root 0 Feb 8 01:18 softirqs
-r--r--r-- 1 root root 0 Feb 8 01:18 stat
-r--r--r-- 1 root root 0 Feb 7 17:54 swaps
dr-xr-xr-x 1 root root 0 Feb 7 17:54 sys
--w------- 1 root root 0 Feb 8 01:18 sysrq-trigger
dr-xr-xr-x 2 root root 0 Feb 8 01:18 sysvipc
-r--r--r-- 1 root root 0 Feb 8 01:18 timer_list
-rw-r--r-- 1 root root 0 Feb 8 01:18 timer_stats
dr-xr-xr-x 4 root root 0 Feb 8 01:18 tty
-r--r--r-- 1 root root 0 Feb 8 01:18 uptime
-r--r--r-- 1 root root 0 Feb 8 01:18 version
-r-------- 1 root root 0 Feb 8 01:18 vmallocinfo
-r--r--r-- 1 root root 0 Feb 8 01:18 vmstat
-r--r--r-- 1 root root 0 Feb 8 01:18 zoneinfo

 

2、/proc/<PID>

每个数字命名的文件实际上是一个进程,进程可能是一个shell命令。
查看进程下相关文件可以获取进程的详细信息。进程文件大小为0如何看到进程详细信息的呢?进程下这些文件可以看做这个是一个内核的窗口,这些文件并不包含一些数据,他实际上是指向进程信息的一个指针。

[root@localhost 460]# ls -lah /proc/1600/
total 0
dr-xr-xr-x 9 root root 0 Feb 7 19:27 .
dr-xr-xr-x 628 root root 0 Feb 7 17:54 ..
dr-xr-xr-x 2 root root 0 Feb 8 01:18 attr
-rw-r--r-- 1 root root 0 Feb 8 01:18 autogroup
-r-------- 1 root root 0 Feb 8 01:18 auxv
-r--r--r-- 1 root root 0 Feb 8 01:18 cgroup
--w------- 1 root root 0 Feb 8 01:18 clear_refs
-r--r--r-- 1 root root 0 Feb 7 19:27 cmdline
-rw-r--r-- 1 root root 0 Feb 8 01:18 comm
-rw-r--r-- 1 root root 0 Feb 8 01:18 coredump_filter
-r--r--r-- 1 root root 0 Feb 8 01:18 cpuset
lrwxrwxrwx 1 root root 0 Feb 8 01:18 cwd -> /
-r-------- 1 root root 0 Feb 8 01:18 environ
lrwxrwxrwx 1 root root 0 Feb 8 01:18 exe -> /usr/sbin/sshd
dr-x------ 2 root root 0 Feb 8 01:18 fd
dr-x------ 2 root root 0 Feb 8 01:18 fdinfo
-rw-r--r-- 1 root root 0 Feb 8 01:18 gid_map
-r-------- 1 root root 0 Feb 8 01:18 io
-r--r--r-- 1 root root 0 Feb 8 01:18 limits
-rw-r--r-- 1 root root 0 Feb 8 01:18 loginuid
dr-x------ 2 root root 0 Feb 8 01:18 map_files
-r--r--r-- 1 root root 0 Feb 8 01:18 maps
-rw------- 1 root root 0 Feb 8 01:18 mem
-r--r--r-- 1 root root 0 Feb 8 01:18 mountinfo
-r--r--r-- 1 root root 0 Feb 8 01:18 mounts
-r-------- 1 root root 0 Feb 8 01:18 mountstats
dr-xr-xr-x 6 root root 0 Feb 8 01:18 net
dr-x--x--x 2 root root 0 Feb 8 01:18 ns
-r--r--r-- 1 root root 0 Feb 8 01:18 numa_maps
-rw-r--r-- 1 root root 0 Feb 8 01:18 oom_adj
-r--r--r-- 1 root root 0 Feb 8 01:18 oom_score
-rw-r--r-- 1 root root 0 Feb 8 01:18 oom_score_adj
-r--r--r-- 1 root root 0 Feb 8 01:18 pagemap
-r-------- 1 root root 0 Feb 8 01:18 patch_state
-r--r--r-- 1 root root 0 Feb 8 01:18 personality
-rw-r--r-- 1 root root 0 Feb 8 01:18 projid_map
lrwxrwxrwx 1 root root 0 Feb 8 01:18 root -> /
-rw-r--r-- 1 root root 0 Feb 8 01:18 sched
-r--r--r-- 1 root root 0 Feb 8 01:18 schedstat
-r--r--r-- 1 root root 0 Feb 8 01:18 sessionid
-rw-r--r-- 1 root root 0 Feb 8 01:18 setgroups
-r--r--r-- 1 root root 0 Feb 8 01:18 smaps
-r--r--r-- 1 root root 0 Feb 8 01:18 stack
-r--r--r-- 1 root root 0 Feb 7 23:54 stat
-r--r--r-- 1 root root 0 Feb 7 23:54 statm
-r--r--r-- 1 root root 0 Feb 7 19:27 status
-r--r--r-- 1 root root 0 Feb 8 01:18 syscall
dr-xr-xr-x 3 root root 0 Feb 8 01:18 task
-r--r--r-- 1 root root 0 Feb 8 01:18 timers
-rw-r--r-- 1 root root 0 Feb 8 01:18 uid_map
-r--r--r-- 1 root root 0 Feb 8 01:18 wchan
[root@localhost 460]#

 

2.1、/proc/<PID>/cmdline

命令行参数

2.2、/proc/<PID>/cpu

当前或最后执行这个进程的cpu

2.3、/proc/<PID>/cwd

链接到当前的进程工作目录(一般为/根目录)

2.4、/proc/<PID>/environ

进程运行时的环境变量

2.5、/proc/<PID>/exe

链接到此进程的可执行文件

2.6、/proc/<PID>/fd

包含进程所使用的所有文件

2.7、/proc/<PID>/maps

可执行文件或库映射的memory

2.8、/proc/<PID>/mem

此进程使用的memory

2.9、/proc/<PID>/root

此进程链接到root用户目录

2.10、/proc/<PID>/stat

此进程的状态

2.11、/proc/<PID>/statm

进程 memory 状态信息

2.12、/proc/<PID>/status

人们便读的进程状态信息

3、/proc/interrupts

 

/proc/interrupts
[root@(none) ~]# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3 CPU4 CPU5
1: 0 0 0 0 0 0 GICv3 25 Level vgic
3: 0 0 0 0 0 0 GICv3 30 Level kvm guest ptimer
4: 0 0 0 0 0 0 GICv3 27 Level kvm guest vtimer
5: 101996856 80352917 80376035 80376004 80375984 80375935 GICv3 26 Level arch_timer
6: 0 0 0 0 0 0 GICv3 23 Level arm-pmu
7: 3570 0 0 0 0 0 GICv3 32 Level uart-pl011
11: 0 0 0 0 0 0 GICv3 40 Level 8020000a0000.watch-dog
12: 0 0 0 0 0 0 ITS-pMSI 0 Edge arm-smmu-v3-evtq
13: 0 0 0 0 0 0 ITS-pMSI 1 Edge arm-smmu-v3-gerror
14: 3 0 0 0 0 0 ITS-MSI 786432 Edge cgx_fwi_0_0
23: 1 0 0 0 0 0 ITS-MSI 786441 Edge cgx_fwi_0_1
32: 1 0 0 0 0 0 ITS-MSI 786450 Edge cgx_fwi_0_2
41: 1 0 0 0 0 0 ITS-MSI 786459 Edge cgx_fwi_0_3
53: 4 0 0 0 0 0 ITS-MSI 268959745 Edge RVUAF FLR
54: 14 0 0 0 0 0 ITS-MSI 268959746 Edge RVUAF ME
56: 344 0 0 0 0 0 ITS-MSI 268959748 Edge RVUAF Mbox
57: 0 0 0 0 0 0 ITS-MSI 268959749 Edge RVUAFVF FLR0
58: 0 0 0 0 0 0 ITS-MSI 268959750 Edge RVUAFVF FLR1
59: 8 0 0 0 0 0 ITS-MSI 268959751 Edge RVUAFVF ME0
60: 0 0 0 0 0 0 ITS-MSI 268959752 Edge RVUAFVF ME1
61: 40 0 0 0 0 0 ITS-MSI 268959753 Edge RVUAFVF Mbox0
62: 0 0 0 0 0 0 ITS-MSI 268959754 Edge RVUAFVF Mbox1

 

表示正在使用的中断

/proc/interrupts文件是动态收集相关数据并显示的。

4、/proc/apm

高级电源管理信息

5、/proc/bus

包含总线细节信息的文件夹

6、/proc/cmdline

内核传参命令行

7、/proc/cpuinfo

包含处理器相关信息,例如类型、组装、模型、性能

8、/proc/devices

罗列当前运行内核配置了驱动的设备(block和character)

9、/proc/dma

显示此时正在使用的dma

10、/proc/driver

各种驱动,但是当前为rtc

11、/proc/execdomains

Execdomains,与安全相关

12、/proc/fd

帧缓存设备

13、/proc/filesystems

内核配置的或支持的文件系统

14、/proc/fs

文件系统参数,当前是nfs/exports

15、/proc/ide

此子目录包含所有内核扫描到的IDE设备信息,每一个IDE控制器、驱动、IDE设备均有一

个子目录,指向控制器子树下的设备文件。

驱动文件包含IDE设备使用的驱动信息。可以在控制器子目录里有更详细信息。他们被命令为ide0、ide1,这些文件包含这些内容。

 /*ide  未完**/

16、/proc/interrupts

显示正在使用的中断,以及显示每个中断发生的次数。

16.1 LOC&&ERR

在2.4内核以后,此文件添加了LOC&&ERR(这个是SMP的输出)

[root@localhost test_ko]# cat /proc/interrupts   | grep  -E "ERR|LOC"
 LOC: 2353386190 1084063652 2337597268  216915500  230618715        919        906        899       1270        887    2109515 2705850549 2109366693  569896502  378720244  168888984  516221152  618341020  811559772 1203516526 2095021535 2124590049    2329475        736 2103896360 2081289857        714        708        702        696        690        683 2111935120        657        652        644        638        631        625 2124611949   Local timer interrupts
 ERR:          0
NMI 是不断增加的每一个timer 中断都会产生一个NMI(NMI 不可屏蔽中断),NMI watchdog 可以使用它来监测。
LOC 是每个cpu内部APIC的一个本地中断计数器(local interrupts)
IO-APIC bus 出错会导致ERR 增加(IO-APIC bus是SMP系统连接cpu之间的总线),这意味着ERR错误出现,IO-APIC会自动尝试重传,这个问题不严重,但也需要关注SMP-FAQ。

16.2 affinity

2.4 内核新增一个文件,这个文件可以可以设置IRQ 和 CPU 的affinity,可以将一个中断只绑定在一个cpu上,或将某cpu排除在处理IRQ的cpu之外。/proc/irq 里面包含中断子目录以及一个default_smp_affinity文件(kernel 2.6 应该是prof_cpu_mask)

[root@localhost test_ko]# ls /proc/irq/
0  10   105  107  109  110  12  14  16  24  27  3   31  33  35  37  39  40  44  50  6  8  default_smp_affinity
1  104  106  108  11   111  13  15  2   25  29  30  32  34  36  38  4   42  5   51  7  9
[root@localhost test_ko]# cat /proc/irq/0/smp_affinity
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001

default_smp_affinity 和 smp_affinity 里面为cpu 掩码形式(bitmask),想设置哪些cpu可以处理中断,可以echo cpu_mask > default_smp_affinity

 echo 1 > /proc/irq/prof_cpu_mask

 

上面意味着第一个cpu能处理中断,echo 5 代表着第一个、第三个cpu可以处理中断,IRQ的route是由IO_APIC决定的,它允许处理IRQ在所有允许的CPU之间循环。由于内核很多的job、information 需要处理,所以默认是所有cpu均可处理。

17、/proc/iomem

Memory 映射

18、/proc/ioports

此时正在使用的 I/O ports

19、/proc/irq

标识irq的affinity

20、/proc/isapnp

ISA PnP (Plug&Play) Info.

21、/proc/kcore

此系统物理内存存储的Image(ELF或A.OUT A.OUT 2.4已经被弃用),与物理内存实际占用相同,但不会占用太多内存,他是在程序访问时动态生成的(除非将其拷贝到其他地方,否则/proc 下文件基本上不会占用disk存储)

22、/proc/kmsg

内核输出的信息,这些信息也会route到syslog

23、/proc/ksyms、/proc/kallsyms

内核符号表

24、/proc/meminfo

内存使用的相关信息,包括物理内存和swap交换分区内存。此文件会产生‘free’或'top'前面几行一样的结果

25、/proc/misc

misc杂项设备相关信息,在proc 文件系统这些信息这些信息没有实际的空间。

26、/proc/modules

内核最近加载的modules,它输出内容同‘lsmod’相同

27、/proc/mounts

挂载的文件系统

28、/proc/mtrr

 

29、/proc/net

网络控制相关信息

 

 未完!!!

参考:

https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

man proc 可以查看更多详细信息

posted on 2023-02-09 19:19  红旗kernel  阅读(227)  评论(0编辑  收藏  举报

导航