首页 > 其他分享 >proc 文件系统

proc 文件系统

时间:2023-02-09 19:22:05浏览次数:36  
标签:01 Feb -- proc 文件系统 18 xr root

1、简介

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

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

 

[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

 

 

 

参考:

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

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

标签:01,Feb,--,proc,文件系统,18,xr,root
From: https://www.cnblogs.com/tzj-kernel/p/17099771.html

相关文章