Procfs and Sysfs
Procfs and Sysfs Filesystems
What is Procfs?
Procfs or "/proc" is a special filesystem under Linux that is used to present process information and kernel processes. Although "/proc" is still used widely, much of the information found on systems running with a kernel level of 2.6 and above have been moved to another pseudo filesystem called "sysfs" which is generally mounted under "/sys". "/proc" is stored in memory, unlike other filesystems, which
are stored on disk. If you list the "/proc" filesystem, you will notice that the majority of files are of a "0" byte length. However, if you view the contents of the file, you will see that there is quite a substantial amount of information within.
john@john-desktop:~$ file /proc/uptime
/proc/uptime: empty
john@john-desktop:~$ cat /proc/uptime
5151.72 2053.73
Below is an example of "/proc" found on an Ubuntu 12.04 system. The trailing backslash "/" signifies a directory:
john@john-desktop:/proc$ ls -F
1/ 1800/ 2016/ 2290/ 2857/ 45/ cpuinfo mounts@
10/ 1818/ 2029/ 2297/ 2861/ 584/ crypto mtrr
1003/ 1855/ 2033/ 23/ 2862/ 6/ devices net@
1042/ 1866/ 2083/ 2320/ 2932/ 613/ device-tree/ pagetypeinfo
11/ 19/ 21/ 2322/ 298/ 619/ diskstats partitions
1105/ 1906/ 2111/ 2324/ 299/ 64/ dma sched_debug
1116/ 1909/ 2120/ 2326/ 3/ 668/ dri/ schedstat
1129/ 1910/ 2122/ 233/ 3039/ 669/ driver/ scsi/
1153/ 1914/ 2136/ 234/ 3046/ 670/ execdomains self@
1154/ 1916/ 2138/ 2370/ 3141/ 691/ fb slabinfo
1156/ 1925/ 2151/ 2371/ 3149/ 698/ filesystems softirqs
1174/ 1934/ 2191/ 24/ 3189/ 7/ fs/ stat
1176/ 1942/ 22/ 2427/ 3208/ 780/ interrupts swaps
1177/ 1952/ 2201/ 2433/ 3229/ 791/ iomem sys/
1181/ 1954/ 2209/ 25/ 325/ 8/ ioports sysrq-trigger
1187/ 1955/ 2210/ 2503/ 3257/ 821/ irq/ sysvipc/
12/ 1956/ 2213/ 2508/ 326/ 823/ kallsyms timer_list
1214/ 1957/ 2220/ 2555/ 3280/ 9/ kcore timer_stats
1240/ 1958/ 2225/ 26/ 344/ 938/ key-users tty/
13/ 1960/ 2226/ 2646/ 35/ 973/ kmsg uptime
1303/ 1961/ 2243/ 2653/ 37/ 982/ kpagecount version
14/ 1964/ 2247/ 2654/ 38/ 988/ kpageflags version_signature
15/ 1967/ 2250/ 2655/ 4/ acpi/ latency_stats vmallocinfo
1586/ 1998/ 2262/ 2659/ 40/ asound/ loadavg vmstat
16/ 2/ 2263/ 2660/ 41/ buddyinfo locks zoneinfo
1602/ 2000/ 2269/ 27/ 42/ bus/ mdstat
17/ 2002/ 2278/ 2848/ 425/ cgroups meminfo
1768/ 201/ 2285/ 2852/ 43/ cmdline misc
18/ 2013/ 2288/ 2856/ 444/ consoles modules
The numbers represent a process (PID - Process ID). Each of these numbers is a directory. Within each of these numbered directories are further files that contain information about the running process. For example the bash shell I am currently running has a PID of "2862". We can "cd" to that directory and take a look:
john@john-desktop:/proc/2862$ ls -F
attr/ coredump_filter io mounts pagemap stack
autogroup cpuset latency mountstats personality stat
auxv cwd@ limits net/ root@ statm
cgroup environ loginuid ns/ sched status
clear_refs exe@ maps oom_adj schedstat syscall
cmdline fd/ mem oom_score sessionid task/
comm fdinfo/ mountinfo oom_score_adj smaps wchan
Brief explanation of some of the notable entries:
cmdline : Contains the command that originally started the process.
cwd : a symbolic link to the current working directory of the process
lrwxrwxrwx 1 john john 0 May 18 21:16 cwd -> /proc/2862
environ : This file contains variable information relating to the process
exe : a symbolic link pointing to the original executable file
lrwxrwxrwx 1 john john 0 May 18 21:16 exe -> /bin/bash
fd :Is a directory that contains symbolic links for each open file descriptor:
john@john-desktop:/proc/2862/fd$ ls -l
total 0
lr-x------ 1 john john 64 May 18 20:31 0 -> /dev/pts/0
l-wx------ 1 john john 64 May 18 20:31 1 -> /dev/pts/0
l-wx------ 1 john john 64 May 18 20:31 2 -> /dev/pts/0
lrwx------ 1 john john 64 May 18 20:36 255 -> /dev/pts/0
fdinfo : A directory that contains files that relate to each open file descriptor found in "/fd"
maps : A file containing information about mapped files and blocks
mem : A binary file that represents the processes virtual memory
root : A symbolic link to the root path as seen by the process
status : A file that contains information relating to the process regarding its current run state and memory usage
task : This directory contains links to any tasks that have been started by this process
Important Directories to know
At times it useful to know where to find information about your system quickly. You may wish to find memory information or information regarding your CPUs present on your system. This information can be found under "/proc". Many utilities and programs will read the information contained in many of these directory structures and report this back to your screen.
Below is a list of some of most useful to know directories:
/proc/fb : List of available frame buffers
/proc/cpuinfo : Lists information about your systems CPU - Family, vendor information, Model number, Core Speeds and CPU flag information.
/proc/devices : Contains a list of character and block devices
/proc/diskstats : Lists information relating to Logical Disk Devices
/proc/filesystems : List of filesystems that are supported by the kernel
/proc/interrupts : Interrupt information can be found here
/proc/iomem : Contains a map of the systems memory for each physical device
/proc/ioports : Contains a list of currently registered port regions used for input or output communication with a device.
/proc/irq : This directory contains directories that correspond to IRQs present on your system. SMP affinity information may be modified here.
/proc/meminfo : Contains kernel memory information
/proc/modules : Contains currently loaded modules within the kernel. "lsmod" command obtains its information from here
/proc/mounts : Contains information regarding mounts. Filesystems in use and what mount options are in use are also listed
/proc/net : Network stack information
/proc/partitions : A list of the device numbers, their size and their /dev names which the kernel has identified as a partition
/proc/slabinfo : Contains kernel slab statistics
/proc/swaps : List of active swap partitions and their size
/proc/sys : Dynamically configurable kernel options can be found here
/proc/uptime : The amount of time in seconds the kernel has been running since boot time and spent in idle mode.
/proc/version : Contains kernel information, version number, gcc version number used for building the kernel
What is sysfs?
Many newer distributions of Linux are using "sysfs" mounted on /sys as a way of exporting information from the kernel to various applications. "sysfs" generally contains nine top level directories:
john@john-desktop:/sys$ ls -l
total 0
drwxr-xr-x 2 root root 0 May 18 20:16 block
drwxr-xr-x 23 root root 0 May 18 20:16 bus
drwxr-xr-x 46 root root 0 May 18 20:16 class
drwxr-xr-x 4 root root 0 May 18 20:16 dev
drwxr-xr-x 15 root root 0 May 18 20:16 devices
drwxr-xr-x 4 root root 0 May 18 20:16 firmware
drwxr-xr-x 7 root root 0 May 18 20:16 fs
drwxr-xr-x 6 root root 0 May 18 20:16 kernel
drwxr-xr-x 121 root root 0 May 18 20:16 module
drwxr-xr-x 2 root root 0 May 18 20:16 power
Brief explanation of directories within "/sys"
/sys/block : Contains known block devices
/sys/bus : Contains all registered buses.
/sys/class : Contains Devices
/sys/device : All devices known by the kernel organised by the bus that they connect to
/sys/firmware : Contains firmware files for some devices
/sys/fs : Contains files to control filesystems
/sys/kernel : Various kernel related files
/sys/module : Loaded kernel modules. Each module is represented by a directory of the same name.
/sys/power : Various files to handle power state of system