Linux的proc文件系统详解
- - 博客园_iTech's BlogLinux系统上的/proc目录是一种文件系统,即proc文件系统. 与其它常见的文件系统不同的是,/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 ………… |
[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 ( [email protected]) (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 ………… |
为系统上特殊设备提供参数信息文件的目录,其不同设备的信息文件分别存储于不同的子目录中,如大多数系统上都会具有的/proc/sys/dev/cdrom和/proc/sys/dev/raid(如果内核编译时开启了支持raid的功能) 目录,其内存储的通常是系统上cdrom和raid的相关参数信息文件。