The /proc Filesystem

Unix systems have come a long way with respect to providing uniform interfaces to different parts of the system; as you learned in Chapter 4, hardware is represented in Linux in the form of a special type of file in the /dev directory. We’ll have a lot more to say about this directory in "Device Files,” later in this chapter. There is, however, a special filesystem called the /proc filesystem that goes even one step further: it unifies files and processes.

From the user’s or the system administrator’s point of view, the /proc filesystem looks just like any other filesystem; you can navigate around it with the cd command, list directory contents with the ls command, and view file contents with the cat command. However, none of these files and directories occupies any space on your hard disk. The kernel traps accesses to the /proc filesystem and generates directory and file contents on the fly. In other words, whenever you list a directory or view file contents in the /proc filesystem, the kernel dynamically generates the contents you want to see.

To make this less abstract, let’s see some examples. The following example displays the list of files in the top-level directory of the /proc filesystem:

    tigger # ls /proc . 3759 5538 5679 5750 6137 9 filesystems net .. 3798 5539 5681 5751 6186 966 fs partitions 1 3858 5540 5683 5754 6497 acpi ide scsi 10 3868 5541 5686 5757 6498 asound interrupts self 11 3892 5542 5688 5759 6511 bluetooth iomem slabinfo 1138 3898 5556 ...

Get Running Linux, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.