版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Longyu_wlz/article/details/56831218
使用/proc文件系统
- 什么是/proc?
man 5 proc
PROC(5) Linux Programmer's Manual PROC(5)
NAME
proc - process information pseudo-filesystem
PROC - 进程信息伪文件系统
DESCRIPTION 描述
The proc filesystem is a pseudo-filesystem which provides an interface to kernel data structures. It is commonly mounted at /proc. Most of it is read-only, but some files allow kernel variables to be changed.
proc文件系统是一个提供给用户内核数据结构接口的伪文件系统。它一般被挂载到/proc目录下。/proc 目录下的大部分文件是只读的,但是通过修改一些文件使用户能够修改内核变量。
/proc 目录实例
/proc/interrupts文件
/proc/interrupts
This is used to record the number of interrupts per CPU per IO device. Since Linux 2.6.24, for the i386 and x86_64 architectures, at least, this also includes interrupts internal to the system (that is, not associated with a device as such), such as NMI (nonmaskable interrupt), LOC (local timer interrupt), and for SMP systems, TLB (TLB flush interrupt), RES(rescheduling interrupt), CAL (remote function call interrupt), and possibly others. Very easy to read formatting, done in ASCII.
/proc/interrupts文件被用来记录每个CPU的每个IO设备的中断的次数。从linux 2.6.24内核开始,对于i386与x86_64架构的机器而言还包括系统内部中断(与设备无关的)。
- /proc/interrupts 文件实例
在上面的图片中,我们可以看出timer占用了中断0,并被CPU0执行过23次对应的中断服务程序!这个数据也可以作为CPU性能指标的衡量。单个CPU中断数越高,表明内核花在中断处理上的时间更长,导致处理其它进程的时间更少。
- /proc/meminfo
This file reports statistics about memory usage on the system. It is used by free(1) to report the amount of free and used memory (both physical and swap) on the system.
这个文件记录了系统上的内存使用情况。这个记录被free程序使用,free程序报告空闲与正在占用的内存的数量(包含物理内存和虚拟内存)
- /proc/meminfo 实例
MemTotal: | 3939372 kB |
---|---|
dMemFree: | 1713548 kB |
MemAvailable: | 2341120 kB |
Buffers: | 51016 kB |
Cached: | 1016524 kB |
SwapCached: | 0 kB |
Active: | 1360708 kB |
- /proc/ioports
- /proc/ioports
- This is a list of currently registered Input-Output port regions that are in use.
这是目前已经登记的正在使用的IO端口区域
- /proc/ioports实例
longyu@debian:/proc$ cat ioports
0000-0cf7 : PCI Bus 0000:00
0000-001f : dma1
0020-0021 : pic1
0040-0043 : timer0
0050-0053 : timer1
0060-0060 : keyboard
0062-0062 : PNP0C09:00
0062-0062 : EC data
0064-0064 : keyboard
0066-0066 : PNP0C09:00
0066-0066 : EC cmd
0070-0077 : rtc0
0080-008f : dma page reg
- 总结
在/proc目录下的文件中保存了进程运行信息,以及内存中内核重要数据结构变量内容,通过访问/proc伪文件系统我们可以了解到当前运行系统的资源配置状况。