- 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统。
Linux系统上的/proc目录是一种文件系统,即proc文件系统。与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。
基于/proc文件系统如上所述的特殊性,其内的文件也常被称作虚拟文件,并具有一些独特的特点。例如,其中有些文件虽然使用查看命令查看时会返回大量信息,但文件本身的大小却会显示为0字节。此外,这些特殊文件中大多数文件的时间及日期属性通常为当前系统时间和日期,这跟它们随时会被刷新(存储于RAM中)有关。 为了查看及使用上的方便,这些文件通常会按照相关性进行分类存储于不同的目录甚至子目录中,如/proc/scsi目录中存储的就是当前系统上所有SCSI设备的相关信息,/proc/N中存储的则是系统当前正在运行的进程的相关信息,其中N为正在运行的进程(可以想象得到,在某进程结束后其相关目录则会消失)。 大多数虚拟文件可以使用文件查看命令如cat、more或者less进行查看,有些文件信息表述的内容可以一目了然,但也有文件的信息却不怎么具有可读性。不过,这些可读性较差的文件在使用一些命令如apm、free、lspci或top查看时却可以有着不错的表现。 一、 进程目录中的常见文件介绍 /proc目录中包含许多以数字命名的子目录,这些数字表示系统当前正在运行进程的进程号,里面包含对应进程相关的多个信息文件。 [root@rhel5 ~]# ll /proc total 0 dr-xr-xr-x 5 root root 0 Feb 8 17:08 1 dr-xr-xr-x 5 root root 0 Feb 8 17:08 10 dr-xr-xr-x 5 root root 0 Feb 8 17:08 11 dr-xr-xr-x 5 root root 0 Feb 8 17:08 1156 dr-xr-xr-x 5 root root 0 Feb 8 17:08 139 dr-xr-xr-x 5 root root 0 Feb 8 17:08 140 dr-xr-xr-x 5 root root 0 Feb 8 17:08 141 dr-xr-xr-x 5 root root 0 Feb 8 17:09 1417 dr-xr-xr-x 5 root root 0 Feb 8 17:09 1418 |
[root@rhel5 ~]# ll /proc/2674 total 0 dr-xr-xr-x 2 root root 0 Feb 8 17:15 attr -r-------- 1 root root 0 Feb 8 17:14 auxv -r--r--r-- 1 root root 0 Feb 8 17:09 cmdline -rw-r--r-- 1 root root 0 Feb 8 17:14 coredump_filter -r--r--r-- 1 root root 0 Feb 8 17:14 cpuset lrwxrwxrwx 1 root root 0 Feb 8 17:14 cwd -> /var/run/saslauthd -r-------- 1 root root 0 Feb 8 17:14 environ lrwxrwxrwx 1 root root 0 Feb 8 17:09 exe -> /usr/sbin/saslauthd dr-x------ 2 root root 0 Feb 8 17:15 fd -r-------- 1 root root 0 Feb 8 17:14 limits -rw-r--r-- 1 root root 0 Feb 8 17:14 loginuid -r--r--r-- 1 root root 0 Feb 8 17:14 maps -rw------- 1 root root 0 Feb 8 17:14 mem -r--r--r-- 1 root root 0 Feb 8 17:14 mounts -r-------- 1 root root 0 Feb 8 17:14 mountstats -rw-r--r-- 1 root root 0 Feb 8 17:14 oom_adj -r--r--r-- 1 root root 0 Feb 8 17:14 oom_score lrwxrwxrwx 1 root root 0 Feb 8 17:14 root -> / -r--r--r-- 1 root root 0 Feb 8 17:14 schedstat -r-------- 1 root root 0 Feb 8 17:14 smaps -r--r--r-- 1 root root 0 Feb 8 17:09 stat -r--r--r-- 1 root root 0 Feb 8 17:14 statm -r--r--r-- 1 root root 0 Feb 8 17:10 status dr-xr-xr-x 3 root root 0 Feb 8 17:15 task -r--r--r-- 1 root root 0 Feb 8 17:14 wchan |
[root@rhel5 ~]# more /proc/2674/cmdline /usr/sbin/saslauthd |
[root@rhel5 ~]# more /proc/2674/environ TERM=linuxauthd |
[root@rhel5 ~]# ll /proc/2674/fd total 0 lrwx------ 1 root root 64 Feb 8 17:17 0 -> /dev/null lrwx------ 1 root root 64 Feb 8 17:17 1 -> /dev/null lrwx------ 1 root root 64 Feb 8 17:17 2 -> /dev/null lrwx------ 1 root root 64 Feb 8 17:17 3 -> socket:[7990] lrwx------ 1 root root 64 Feb 8 17:17 4 -> /var/run/saslauthd/saslauthd.pid lrwx------ 1 root root 64 Feb 8 17:17 5 -> socket:[7991] lrwx------ 1 root root 64 Feb 8 17:17 6 -> /var/run/saslauthd/mux.accept |
[root@rhel5 ~]# cat /proc/2674/maps 00110000-00239000 r-xp 00000000 08:02 130647 /lib/libcrypto.so.0.9.8e 00239000-0024c000 rwxp 00129000 08:02 130647 /lib/libcrypto.so.0.9.8e 0024c000-00250000 rwxp 0024c000 00:00 0 00250000-00252000 r-xp 00000000 08:02 130462 /lib/libdl-2.5.so 00252000-00253000 r-xp 00001000 08:02 130462 /lib/libdl-2.5.so |
[root@rhel5 ~]# more /proc/2674/status Name: saslauthd State: S (sleeping) SleepAVG: 0% Tgid: 2674 Pid: 2674 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 32 Groups: VmPeak: 5576 kB VmSize: 5572 kB VmLck: 0 kB VmHWM: 696 kB VmRSS: 696 kB ………… |
[root@rhel5 ~]# more /proc/cmdline ro root=/dev/VolGroup00/LogVol00 rhgb quiet |
[root@rhel5 ~]# more /proc/crypto name : crc32c driver : crc32c-generic module : kernel priority : 0 type : digest blocksize : 32 digestsize : 4 ………… |
[root@rhel5 ~]# more /proc/devices Character devices: 1 mem 4 /dev/vc/0 4 tty 4 ttyS ………… Block devices: 1 ramdisk 2 fd 8 sd ………… |
[root@rhel5 ~]# more /proc/dma 2: floppy 4: cascade |
[root@rhel5 ~]# more /proc/execdomains 0-0 Linux [kernel] |
[root@rhel5 ~]# more /proc/filesystems nodev sysfs nodev rootfs nodev proc iso9660 ext3 ………… ………… |
[root@rhel5 ~]# more /proc/interrupts CPU0 0: 1305421 IO-APIC-edge timer 1: 61 IO-APIC-edge i8042 185: 1068 IO-APIC-level eth0 ………… |
[root@rhel5 ~]# more /proc/iomem 00000000-0009f7ff : System RAM 0009f800-0009ffff : reserved 000a0000-000bffff : Video RAM area 000c0000-000c7fff : Video ROM ………… |
3.2.12. /proc/iomem
This file shows you the current map of the system's memory for each physical device:
00000000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000a0000-000bffff : Video RAM area
000c0000-000c7fff : Video ROM
000f0000-000fffff : System ROM
00100000-07ffffff : System RAM
00100000-00291ba8 : Kernel code
00291ba9-002e09cb : Kernel data
e0000000-e3ffffff : VIA Technologies, Inc. VT82C597 [Apollo VP3] e4000000-e7ffffff : PCI Bus #01
e4000000-e4003fff : Matrox Graphics, Inc. MGA G200 AGP
e5000000-e57fffff : Matrox Graphics, Inc. MGA G200 AGP
e8000000-e8ffffff : PCI Bus #01
e8000000-e8ffffff : Matrox Graphics, Inc. MGA G200 AGP
ea000000-ea00007f : Digital Equipment Corporation DECchip 21140 [FasterNet]
ea000000-ea00007f : tulip ffff0000-ffffffff : reserved
The first column displays the memory registers used by each of the different types of memory. The second column lists the kind of memory located within those registers and displays which memory registers are used by the kernel within the system RAM or, if the network interface card has multiple Ethernet ports, the memory registers assigned for each port.
/opt/qtmarvell/mvqt # cat /proc/iomem
00000000-0fffffff : System RAM 0002b000-00554fff : Kernel text 00556000-005a22f3 : Kernel data 10000000-1fffffff : System RAM e0000000-e7ffffff : PEX0 Memory e0000000-e0003fff : 0000:00:01.0 e0004000-e0004fff : 0000:00:01.0 e8000000-efffffff : PEX1 Memory f1012100-f10121ff : serial8250.0 f1012100-f101211f : serial f1090000-f10903ff : mvsdio f1090000-f10903ff : mvsdio f10a0000-f10a3fff : mv88fx_snd.0 f10a0000-f10a3fff : mv88fx_snd f10c0000-f10d0000 : dovefb.0 寄存器地址映射到这个 f10c0000-f10d0000 : dovefb_ovly.0
/opt/qtmarvell/mvqt # ./framebuffer
The framebuffer device was opened successfully.Fixed screen info:
id: GFX Layer 0 smem_start: 0x12000000 smem_len: 33554432 type: 0 type_aux: 0 visual: 2 xpanstep: 1 ypanstep: 1 ywrapstep: 0 line_length: 2560 mmio_start: 0xf10c0000 mmio_len: 65537 2.14、/proc/ioports 当前正在使用且已经注册过的与物理设备进行通讯的输入-输出端口范围信息列表;如下面所示,第一列表示注册的I/O端口范围,其后表示相关的设备; [root@rhel5 ~]# less /proc/ioports 0000-001f : dma1 0020-0021 : pic1 0040-0043 : timer0 0050-0053 : timer1 0060-006f : keyboard ………… |
[root@rhel5 ~]# more /proc/kallsyms c04011f0 T _stext c04011f0 t run_init_process c04011f0 T stext ………… |
[root@rhel5 ~]# more /proc/loadavg 0.45 0.12 0.04 4/125 5549 [root@rhel5 ~]# uptime 06:00:54 up 1:06, 3 users, load average: 0.45, 0.12, 0.04 |
[root@rhel5 ~]# more /proc/locks 1: POSIX ADVISORY WRITE 4904 fd:00:4325393 0 EOF 2: POSIX ADVISORY WRITE 4550 fd:00:2066539 0 EOF 3: FLOCK ADVISORY WRITE 4497 fd:00:2066533 0 EOF |
[root@rhel5 ~]# less /proc/mdstat Personalities : unused devices: <none> |
[root@rhel5 ~]# less /proc/meminfo MemTotal: 515492 kB MemFree: 8452 kB Buffers: 19724 kB Cached: 376400 kB SwapCached: 4 kB ………… |
[root@rhel5 ~]# ll /proc |grep mounts lrwxrwxrwx 1 root root 11 Feb 8 06:43 mounts -> self/mounts |
[root@rhel5 ~]# more /proc/mounts rootfs / rootfs rw 0 0 /dev/root / ext3 rw,data=ordered 0 0 /dev /dev tmpfs rw 0 0 /proc /proc proc rw 0 0 /sys /sys sysfs rw 0 0 /proc/bus/usb /proc/bus/usb usbfs rw 0 0 ………… |
[root@rhel5 ~]# more /proc/modules autofs4 24517 2 - Live 0xe09f7000 hidp 23105 2 - Live 0xe0a06000 rfcomm 42457 0 - Live 0xe0ab3000 l2cap 29505 10 hidp,rfcomm, Live 0xe0aaa000 ………… |
[root@rhel5 ~]# more /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 104391 sda1 8 2 6907950 sda2 8 3 5630782 sda3 8 4 1 sda4 8 5 3582463 sda5 |
[root@rhel5 ~]# more /proc/slabinfo slabinfo - version: 2.1 # name <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> <batchcount> <sharedfactor> : slabdata <ac tive_slabs> <num_slabs> <sharedavail> rpc_buffers 8 8 2048 2 1 : tunables 24 12 8 : slabdata 4 4 0 rpc_tasks 8 20 192 20 1 : tunables 120 60 8 : slabdata 1 1 0 rpc_inode_cache 6 9 448 9 1 : tunables 54 27 8 : slabdata 1 1 0 ………… ………… ………… |
[root@rhel5 ~]# more /proc/stat cpu 2751 26 5771 266413 2555 99 411 0 cpu0 2751 26 5771 266413 2555 99 411 0 intr 2810179 2780489 67 0 3 3 0 5 0 1 0 0 0 1707 0 0 9620 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12781 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 427300 btime 1234084100 processes 3491 procs_running 1 procs_blocked 0 |
[root@rhel5 ~]# more /proc/swaps Filename Type Size Used Priority /dev/sda8 partition 642560 0 -1 |
[root@rhel5 ~]# more /proc/uptime 3809.86 3714.13 |
[root@rhel5 ~]# more /proc/version Linux version 2.6.18-128.el5 (mockbuild@hs20-bc1-5.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)) #1 SMP Wed Dec 17 11:42:39 EST 2008 |
[root@rhel5 ~]# more /proc/vmstat nr_anon_pages 22270 nr_mapped 8542 nr_file_pages 47706 nr_slab 4720 nr_page_table_pages 897 nr_dirty 21 nr_writeback 0 ………… |
[root@rhel5 ~]# more /proc/zoneinfo Node 0, zone DMA pages free 1208 min 28 low 35 high 42 active 439 inactive 1139 scanned 0 (a: 7 i: 30) spanned 4096 present 4096 nr_anon_pages 192 nr_mapped 141 nr_file_pages 1385 nr_slab 253 nr_page_table_pages 2 nr_dirty 523 nr_writeback 0 nr_unstable 0 nr_bounce 0 protection: (0, 0, 296, 296) pagesets all_unreclaimable: 0 prev_priority: 12 start_pfn: 0 ………… |