CSE Roadmap

Core tier · about 3 hours · 8 parts

Part 2 of 8 · 2 min read

Which system

Think of a doctor, who starts with a few simple measurements: height, weight, pulse. A Linux machine has simple readings too, and most of them are files.

In plain words: Linux provides a /proc file system: a set of directories and files under /proc that look like ordinary files but are really a window onto kernel data. Reading the file asks the kernel for the current value. The contents are mostly plain text, so shell scripts and programs can read them with the same calls they use for other files (page 2).

The key lines.

Try these commands. The output shown is from the test machine, a small virtual machine.

$ uname -sr
Linux 6.18.44-fc-v470
$ nproc
2
$ grep MemTotal /proc/meminfo
MemTotal:        8216668 kB
$ grep -m1 "model name" /proc/cpuinfo
model name  : Intel(R) Xeon(R) Processor @ 2.30GHz

uname -sr prints the kernel name and release. nproc counts the processors available to you. /proc/meminfo lists memory figures in kilobytes (kB, where one kB here is 1,024 bytes). /proc/cpuinfo describes each processor.

A worked example.

A unit conversion shows how to read the number. 8,216,668 kB divided by 1,024 is 8,024 megabytes (to the nearest), and divided by 1,024 again is 7.84 gigabytes. So this machine has about 8 GB of memory, a little of which the kernel keeps for itself. The earlier demo in page 1 used the same machine: two processors, which is why four programs shared them.

The /proc folder tree

/proc is a virtual file system that the Linux kernel builds in memory. Its files and directories are not stored on disk. Reading one makes the kernel generate its contents on the spot from live data about the system and about each process.

Example: reading /proc/meminfo shows how much memory the machine has, as the kernel counts it at that moment.

Check yourself: 1. Which command shows the number of processors? 2. In what unit does /proc/meminfo give sizes? 3. Is a /proc file stored on the disk?