Linux Procfs
What is procfs (and sysfs) and what are they used for?
Overview
There’s a ton of information out there, but here’s what you need to know:
From “Linux Kernel Procfs Guide” by Erik (J.A.K.) Mouw… https://kernelnewbies.org/Documents/Kernel-Docbooks?action=AttachFile&do=get&target=procfs-guide_2.6.29.pdf
The /proc file system (procfs) is a special file system in the linux kernel.
It’s a virtual file system: it is not associated with a block device but exists
only in memory. The files in the procfs are there to allow userland programs
access to certain information from the kernel (like process information in
/proc/[0-9]+/ ), but also for debug purposes (like /proc/ksyms ).
...
Instead of reading (or writing) information directly from kernel memory, procfs
works with call back functions for files: functions that are called when a
specific file is being read or written.
More links:
So basically, procfs and sysfs allow us access to kernel level details via a file-system-like API. Everything is a file.
Documentation
There is this magical kindom called Kernel.org, and in that kingdom, they have documentation…
https://www.kernel.org/doc/Documentation/filesystems/proc.txt
------------------------------------------------------------------------------
T H E /proc F I L E S Y S T E M
------------------------------------------------------------------------------
Kernel.org is a documentation dream. Section 1.8 deals with what we are interested in, /proc/stat
:
1.8 Miscellaneous kernel statistics in /proc/stat
Paging down to that section, we see the nuts and bolts of how this works:
1.8 Miscellaneous kernel statistics in /proc/stat
-------------------------------------------------
Various pieces of information about kernel activity are available in the
/proc/stat file. All of the numbers reported in this file are aggregates
since the system first booted. For a quick look, simply cat the file:
Ok, let’s try it…
<pre>$ cat /proc/stat
cpu 1274240 19928 407422 72766108 72703 0 12494 0 0 0
cpu0 188950 2084 56891 10272145 10833 0 6916 0 0 0
cpu1 125875 1620 39109 8952369 19718 0 1321 0 0 0
cpu2 193832 2997 58106 8873354 10000 0 569 0 0 0
cpu3 124766 1828 43418 8964723 5675 0 155 0 0 0
cpu4 194548 2834 58202 8873039 9908 0 130 0 0 0
cpu5 126274 1812 44630 8970546 6717 0 333 0 0 0
cpu6 195927 4164 67449 8882986 5034 0 392 0 0 0
cpu7 124064 2586 39614 8976943 4814 0 2676 0 0 0
intr 77943879 6459077 6315 0 0 0 0 0 0 1 25484 0 0 829151 0 0 0 747 0 16 430 0 0 0 43772 6105365 2416471 6126426 3089783 6233849 833826 0 0 0 0 0 0 0 19 1623130 640778 174 385550 841313 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 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 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
ctxt 220842322
btime 1561498948
processes 58050
procs_running 2
procs_blocked 0
softirq 28105901 2528 9356000 121075 1863721 835876 56 249179 9047058 0 6630408
So it says I have 8 processors on my current laptop, and I do. Check.
Summary
I need to spend more time here.