Exploring the Linux procfs (/proc)

Procfs  is a virtual file system. Every file contained by the procfs is a region of the RAM memory (stored phisically on the RAM) that offers information about the system.

Watch Free Movies

Procfs gives us both, information about the processes running in the system and other specific information, such as: the devices connected, memory information, cpu information etc.

Procfs is mounted in /proc:

The info about the processes is displayed by the directories having numbers as names. Every number is a PID of a process. For example, the directory called 1 represents the init process:

$ cd /proc/1
$ ls -1 | wc
44 44 328

My directory associated with the init process has 44 files and directories inside it.

Example of files and what they “say”:

The exe file is a sym link pointing to init’s path: /sbin/init
$ sudo ls -l /proc/1/exe
lrwxrwxrwx 1 root root 0 2012-06-02 21:34 exe -> /sbin/init

The cmdline file shows us the command that started the process:
$ cat /proc/1/cmdline
/sbin/init

The comm file gives us the process’s name:
$ cat comm
init

The status file displays the process’s state and other info about it:
$ cat /proc/1/status | grep -i state
State: S (sleeping)

The fd directory offers info about the process ran by the current process (init in our case):

$ sudo ls /proc/1/fd
0 1 10 2 3 4 5 6 7 8 9
$ sudo ls -l /proc/1/fd | head -4
total 0
lrwx------ 1 root root 64 2012-06-02 21:50 0 -> /dev/null
lrwx------ 1 root root 64 2012-06-02 21:50 1 -> /dev/null
lrwx------ 1 root root 64 2012-06-02 21:50 10 -> socket:[7018]

Other usefull info that /proc can give us:

The /proc/cmdline gives us the image of the kernel
$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-3.0.0-12-generic root=UUID=f5645214-3a4e-42af-9791-7b1c1aa405e2 ro quiet splash vt.handoff=7

Info about the CPU: /proc/cpuinfo
$cat /proc/cpuinfo | grep "model name"
model name : AMD Phenom(tm) II P960 Quad-Core Processor

Info about the momery: /proc/meminfo
$ cat meminfo | grep -i mem | head -2
MemTotal: 1019124 kB
MemFree: 131868 kB

Info about the partitions: /proc/partitions
$ cat /proc/partitions | tail -4
8 0 20971520 sda
8 1 19921920 sda1
8 2 1 sda2
8 5 1046528 sda5

Info about the swap memory: /proc/swaps
$ cat /proc/swaps
Filename Type Size Used Priority
/dev/sda5 partition 1046524 12220 -1

Info about the uptime: /proc/uptime

Info about the kernel version: /proc/version
$ cat /proc/version
Linux version 3.0.0-12-generic (buildd@crested) (gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)  #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011

A good Linux user should not learn by hearth this info, but know how to find them.

Scroll to Top