首页 > 学院 > 开发设计 > 正文

/PROC目录

2019-11-06 09:30:06
字体:
来源:转载
供稿:网友

参考文档

使用 /PRoc 文件系统来访问 linux 内核的内容

Linux下/proc目录简介

嗯,第一个没看懂


/proc目录简介


1/PROC目录及proc文件系统

/PROC里面的文件是proc文件系统对应的文件.

Linux内核提供了一种通过 proc 文件系统,在运行时访问内核内部数据结构、改变内核设置的机制.

proc文件系统是一个内存文件系统,它只存在内存当中,而不占用外存空间.

在开机前,只存在/proc/目录,目录中无文件

在开机后,proc文件系统将有关进程的信息写入/proc目录中,即创建目录文件和普通文件来标识进程的相关信息.

然后我们可以通过目录中的文件来读取进程相关信息,但部分可以通过写来改变内核环境.?

最初开发 /proc 文件系统是为了提供有关系统中进程的信息。但是由于这个文件系统非常有用,因此内核中的很多元素也开始使用它来报告信息,或启用动态运行时配置。


2/PROC目录中的文件

linux@Ubuntu:/proc$ ls1 14 2189 2289 24 2493 2631 451 663 7481 8041 912 998 fb meminfo sys10 15 22 2290 2407 25 2638 4603 670 7482 8043 915 999 filesystems misc sysrq-trigger1000 1562 2200 2298 2411 2501 2639 4729 7 757 8044 916 acpi fs modules sysvipc1005 16 221 23 2416 2505 2713 5 7145 759 8093 917 asound interrupts mounts timer_list1019 17 2229 2303 2417 2506 2718 522 717 7618 8107 921 buddyinfo iomem mpt timer_stats11 1760 2237 2304 2419 2508 2726 524 7225 7619 8219 923 bus ioports mtrr tty1148 1786 2240 2305 2424 2511 3 540 7226 766 8221 933 cgroups irq net uptime12 18 2241 2315 2426 2512 333 545 733 7675 8346 940 cmdline kallsyms pagetypeinfo version12827 1834 2250 2333 2429 2516 337 591 7385 7679 8351 968 consoles kcore partitions version_signature12918 1969 2261 2341 2432 2541 35 6 7387 769 860 988 cpuinfo key-users sched_debug vmallocinfo12938 2 2263 2350 2435 2542 38 62 7390 790 866 991 crypto kmsg schedstat vmstat12975 204 2269 2353 2436 2544 39 63 7392 792 867 992 devices kpagecount scsi zoneinfo12994 2062 2279 2358 2442 2548 40 631 7394 793 880 993 diskstats kpageflags self13 207 2283 2360 246 2592 42 632 7396 7941 882 994 dma latency_stats slabinfo13016 209 2285 2365 247 26 441 64 7398 7949 887 995 dri loadavg softirqs13059 21 2286 2386 2476 2612 442 646 7400 8 8989 996 driver locks stat1333 210 2288 2392 2492 2630 4484 6609 7402 8039 9 997 execdomains mdstat swaps

3/PROC文件分类

3.1/以数字为名的文件夹

最小的数字为1,最大的数字为四位数,例如8989

linux@ubuntu:/proc$ l /proc/8989/ attr/ clear_refs cpuset fd/ limits mem net/ oom_score_adj sched stack syscallautogroup cmdline cwd@ fdinfo/ loginuid mountinfo ns/ pagemap schedstat stat task/auxv comm environ io map_files/ mounts oom_adj personality sessionid statm wchancgroup coredump_filter exe@ latency maps mountstats oom_score root@ smaps status其中status 当前进程的状态cmdline 程序启动时的命令行

3.2/其他文件夹

dr-xr-xr-x 2 root root 0 2月 23 20:50 acpi/dr-xr-xr-x 5 root root 0 2月 26 10:38 asound/dr-xr-xr-x 4 root root 0 2月 26 10:38 bus/dr-xr-xr-x 3 root root 0 2月 26 10:38 dri/dr-xr-xr-x 2 root root 0 2月 26 10:38 driver/dr-xr-xr-x 8 root root 0 2月 23 20:50 fs/dr-xr-xr-x 56 root root 0 2月 26 10:38 irq/dr-xr-xr-x 3 root root 0 2月 26 10:38 mpt/dr-xr-xr-x 6 linux linux 0 2月 26 10:38 net/dr-xr-xr-x 5 root root 0 2月 26 10:38 scsi/dr-xr-xr-x 1 root root 0 2月 23 20:50 sys/dr-xr-xr-x 2 root root 0 2月 26 10:38 sysvipc/dr-xr-xr-x 4 root root 0 2月 26 10:38 tty/

3.3/普通文件

linux@ubuntu:/proc$ ls -al | grep '^-'-r--r--r-- 1 root root 0 2月 26 10:45 buddyinfo-r--r--r-- 1 root root 0 2月 26 10:45 cgroups-r--r--r-- 1 root root 0 2月 26 10:45 cmdline-r--r--r-- 1 root root 0 2月 26 10:45 consoles-r--r--r-- 1 root root 0 2月 26 10:45 cpuinfo-r--r--r-- 1 root root 0 2月 26 10:45 crypto-r--r--r-- 1 root root 0 2月 26 10:45 devices-r--r--r-- 1 root root 0 2月 26 10:45 diskstats-r--r--r-- 1 root root 0 2月 26 10:45 dma-r--r--r-- 1 root root 0 2月 26 10:45 execdomains-r--r--r-- 1 root root 0 2月 26 10:45 fb-r--r--r-- 1 root root 0 2月 26 10:45 filesystems-r--r--r-- 1 root root 0 2月 26 10:45 interrupts-r--r--r-- 1 root root 0 2月 26 10:45 iomem-r--r--r-- 1 root root 0 2月 26 10:45 ioports-r--r--r-- 1 root root 0 2月 26 10:45 kallsyms-r-------- 1 root root 1069543424 2月 26 10:45 kcore-r--r--r-- 1 root root 0 2月 26 10:45 key-users-r-------- 1 root root 0 2月 23 20:50 kmsg-r-------- 1 root root 0 2月 26 10:45 kpagecount-r-------- 1 root root 0 2月 26 10:45 kpageflags-rw-r--r-- 1 root root 0 2月 26 10:45 latency_stats-r--r--r-- 1 root root 0 2月 26 10:45 loadavg-r--r--r-- 1 root root 0 2月 26 10:45 locks-r--r--r-- 1 root root 0 2月 23 20:51 mdstat-r--r--r-- 1 root root 0 2月 23 20:51 meminfo-r--r--r-- 1 root root 0 2月 26 10:45 misc-r--r--r-- 1 root root 0 2月 26 10:45 modules-rw-r--r-- 1 root root 0 2月 23 20:50 mtrr-r--r--r-- 1 root root 0 2月 26 10:45 pagetypeinfo-r--r--r-- 1 root root 0 2月 26 10:45 partitions-r--r--r-- 1 root root 0 2月 26 10:45 sched_debug-r--r--r-- 1 root root 0 2月 26 10:45 schedstat-r-------- 1 root root 0 2月 26 10:45 slabinfo-r--r--r-- 1 root root 0 2月 26 10:45 softirqs-r--r--r-- 1 root root 0 2月 23 20:51 stat-r--r--r-- 1 root root 0 2月 26 10:45 swaps--w------- 1 root root 0 2月 26 10:45 sysrq-trigger-r--r--r-- 1 root root 0 2月 26 10:45 timer_list-rw-r--r-- 1 root root 0 2月 26 10:45 timer_stats-r--r--r-- 1 root root 0 2月 26 10:45 uptime-r--r--r-- 1 root root 0 2月 26 10:45 version-r--r--r-- 1 root root 0 2月 26 10:45 version_signature-r-------- 1 root root 0 2月 26 10:45 vmallocinfo-r--r--r-- 1 root root 0 2月 23 20:51 vmstat-r--r--r-- 1 root root 0 2月 26 10:45 zoneinfo档名 文件内容/proc/cmdline 加载 kernel 时所下达的相关参数!查阅此文件,可了解系统是如何启动的!/proc/cpuinfo 本机的 CPU 的相关资讯,包含时脉、类型与运算功能等/proc/devices 这个文件记录了系统各个主要装置的主要装置代号,与 mknod 有关呢!/proc/filesystems 目前系统已经加载的文件系统罗!/proc/interrupts 目前系统上面的 IRQ 分配状态。/proc/ioports 目前系统上面各个装置所配置的 I/O 位址。/proc/kcore 这个就是内存的大小啦!好大对吧!但是不要读他啦!/proc/loadavg 还记得 top 以及 uptime 吧?没错!上头的三个平均数值就是记录在此!/proc/meminfo 使用 free 列出的内存资讯,嘿嘿!在这里也能够查阅到!/proc/modules 目前我们的 Linux 已经加载的模块列表,也可以想成是驱动程序啦!/proc/mounts 系统已经挂载的数据,就是用 mount 这个命令呼叫出来的数据啦!/proc/swaps 到底系统挂加载的内存在哪里?呵呵!使用掉的 partition 就记录在此啦!/proc/partitions 使用 fdisk -l 会出现目前所有的 partition 吧?在这个文件当中也有纪录喔!/proc/pci 在 PCI 汇流排上面,每个装置的详细情况!可用 lspci 来查阅!/proc/uptime 就是用 uptime 的时候,会出现的资讯啦!/proc/version 核心的版本,就是用 uname -a 显示的内容啦!/proc/bus/* 一些汇流排的装置,还有 U盘 的装置也记录在此喔!

3.4链接文件

linux@ubuntu:/proc$ ls -al | grep '^l'lrwxrwxrwx 1 root root 11 2月 26 10:46 mounts -> self/mountslrwxrwxrwx 1 root root 8 2月 26 10:46 net -> self/netlrwxrwxrwx 1 root root 64 2月 23 20:50 self -> 13087self文件是个连接,但又好像是个目录在我键入ls的时候,self文件的内容就是ls进程的信息cat /proc/self/status 的时候,打印的信息是cat /proc/self/status进程的信息

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表