17.5 The /proc File System
The /proc file system is a pseudo file system
in which the kernel reserves important information in the form of
virtual files. For example, display the CPU type with
this command:
tester@linux:~> cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 8
model name : AMD Athlon(tm) XP 2400+
stepping : 1
cpu MHz : 2009.343
cache size : 256 KB
fdiv_bug : no
[...]
Query the allocation and use of interrupts with the following
command:
tester@linux:~> cat /proc/interrupts
CPU0
0: 3577519 XT-PIC timer
1: 130 XT-PIC i8042
2: 0 XT-PIC cascade
5: 564535 XT-PIC Intel 82801DB-ICH4
7: 1 XT-PIC parport0
8: 2 XT-PIC rtc
9: 1 XT-PIC acpi, uhci_hcd:usb1, ehci_hcd:usb4
10: 0 XT-PIC uhci_hcd:usb3
11: 71772 XT-PIC uhci_hcd:usb2, eth0
12: 101150 XT-PIC i8042
14: 33146 XT-PIC ide0
15: 149202 XT-PIC ide1
NMI: 0
LOC: 0
ERR: 0
MIS: 0
Some of the important files and their contents are:
-
/proc/devices
-
Available devices
-
/proc/modules
-
Kernel modules loaded
-
/proc/cmdline
-
Kernel command line
-
/proc/meminfo
-
Detailed information about memory usage
-
/proc/config.gz
-
gzip-compressed configuration file of the kernel
currently running
Further information is available in the text file
/usr/src/linux/Documentation/filesystems/proc.txt.
Find information about processes currently running in the
/proc/NNN
directories, where NNN is the process ID
(PID) of the relevant process. Every process can find its own
characteristics in /proc/self/:
tester@linux:~> ls -l /proc/self
lrwxrwxrwx 1 root root 64 2006-01-09 13:03 /proc/self -> 5356
tester@linux:~> ls -l /proc/self/
total 0
dr-xr-xr-x 2 tester users 0 2006-01-09 17:04 attr
-r-------- 1 tester users 0 2006-01-09 17:04 auxv
-r--r--r-- 1 tester users 0 2006-01-09 17:04 cmdline
lrwxrwxrwx 1 tester users 0 2006-01-09 17:04 cwd -> /home/tester
-r-------- 1 tester users 0 2006-01-09 17:04 environ
lrwxrwxrwx 1 tester users 0 2006-01-09 17:04 exe -> /bin/ls
dr-x------ 2 tester users 0 2006-01-09 17:04 fd
-rw-r--r-- 1 tester users 0 2006-01-09 17:04 loginuid
-r--r--r-- 1 tester users 0 2006-01-09 17:04 maps
-rw------- 1 tester users 0 2006-01-09 17:04 mem
-r--r--r-- 1 tester users 0 2006-01-09 17:04 mounts
-rw-r--r-- 1 tester users 0 2006-01-09 17:04 oom_adj
-r--r--r-- 1 tester users 0 2006-01-09 17:04 oom_score
lrwxrwxrwx 1 tester users 0 2006-01-09 17:04 root -> /
-rw------- 1 tester users 0 2006-01-09 17:04 seccomp
-r--r--r-- 1 tester users 0 2006-01-09 17:04 smaps
-r--r--r-- 1 tester users 0 2006-01-09 17:04 stat
-r--r--r-- 1 tester users 0 2006-01-09 17:04 statm
-r--r--r-- 1 tester users 0 2006-01-09 17:04 status
dr-xr-xr-x 3 tester users 0 2006-01-09 17:04 task
-r--r--r-- 1 tester users 0 2006-01-09 17:04 wchan
The address assignment of executables and libraries is contained in the
maps file:
tester@linux:~> cat /proc/self/maps
08048000-0804c000 r-xp 00000000 03:03 17753 /bin/cat
0804c000-0804d000 rw-p 00004000 03:03 17753 /bin/cat
0804d000-0806e000 rw-p 0804d000 00:00 0 [heap]
b7d27000-b7d5a000 r--p 00000000 03:03 11867 /usr/lib/locale/en_GB.utf8/
b7d5a000-b7e32000 r--p 00000000 03:03 11868 /usr/lib/locale/en_GB.utf8/
b7e32000-b7e33000 rw-p b7e32000 00:00 0
b7e33000-b7f45000 r-xp 00000000 03:03 8837 /lib/libc-2.3.6.so
b7f45000-b7f46000 r--p 00112000 03:03 8837 /lib/libc-2.3.6.so
b7f46000-b7f48000 rw-p 00113000 03:03 8837 /lib/libc-2.3.6.so
b7f48000-b7f4c000 rw-p b7f48000 00:00 0
b7f52000-b7f53000 r--p 00000000 03:03 11842 /usr/lib/locale/en_GB.utf8/
[...]
b7f5b000-b7f61000 r--s 00000000 03:03 9109 /usr/lib/gconv/gconv-module
b7f61000-b7f62000 r--p 00000000 03:03 9720 /usr/lib/locale/en_GB.utf8/
b7f62000-b7f76000 r-xp 00000000 03:03 8828 /lib/ld-2.3.6.so
b7f76000-b7f78000 rw-p 00013000 03:03 8828 /lib/ld-2.3.6.so
bfd61000-bfd76000 rw-p bfd61000 00:00 0 [stack]
ffffe000-fffff000 ---p 00000000 00:00 0 [vdso]
17.5.1 procinfo
Important information from the /proc file system is
summarized by the command procinfo:
tester@linux:~> procinfo
Linux 2.6.15-rc5-git3-2-default (geeko@buildhost) (gcc 4.1.0 20051129) #1 Wed
Memory: Total Used Free Shared Buffers
Mem: 515584 509472 6112 0 73024
Swap: 658656 0 658656
Bootup: Mon Jan 9 12:59:08 2006 Load average: 0.10 0.04 0.05 1/86 5406
user : 0:02:07.98 0.8% page in : 442638 disk 1: 20125r 134
nice : 0:02:20.91 0.9% page out: 134950
system: 0:00:42.93 0.3% page act: 70577
IOwait: 0:01:25.40 0.6% page dea: 11696
hw irq: 0:00:08.94 0.1% page flt: 1423622
sw irq: 0:00:01.29 0.0% swap in : 0
idle : 4:06:30.54 97.3% swap out: 0
uptime: 4:13:20.72 context : 3813145
irq 0: 3799268 timer irq 8: 2 rtc
irq 1: 130 i8042 irq 9: 1 acpi, uhci_hcd:usb
irq 2: 0 cascade [4] irq 10: 0 uhci_hcd:usb3
irq 3: 8 irq 11: 75905 uhci_hcd:usb2, eth
irq 4: 8 irq 12: 101150 i8042
irq 5: 564535 Intel 82801DB-ICH4 irq 14: 33733 ide0
irq 6: 9 irq 15: 157045 ide1
irq 7: 1 parport0 [3]
To see all the information, use the parameter -a. The
parameter -nN produces updates of the information every
N seconds. In this case, terminate the program
by pressing Q.
By default, the cumulative values are displayed. The parameter
-d produces the differential values. procinfo
-dn5 displays the values that have changed in the last five
seconds: