Experiment 02 — Exploring the /proc File System

← Back to Index
## Use /proc file system to gather basic information about machine

------
->  /proc file system is a virtual file system in Linux that provides an interface to kernel data structures.

->  contains a hierarchy of les that represent the system's current state ,hardware,
processes, and kernel parameters.

/proc/cpuinfo → Contains details about the CPU(s) including number of cores.

/proc/meminfo → Displays information about system memory usage.

/proc/stat → Provides kernel statistics including number of processes, CPU usage, context switches, etc.

/proc/[pid]/status → Shows information about a specic process (identied by its processID).

/proc/loadavg  → Shows the system load average and number of running processes.

The /proc file system updates dynamically, reflecting real-time system information without
the need for special system calls
-------
>>> cat /proc/cpuinfo | less

>>> grep -c processor /proc/cpuinfo 
>>> cat /proc/cpuinfo | grep  "processor" | wc -l

>>> cat /proc/meminfo


┌──(akhil㉿akhil)-[~]
└─$ cat /proc/meminfo | grep -E 'MemTotal|MemFree'
MemTotal:        3667152 kB
MemFree:         2738700 kB

┌──(akhil㉿akhil)-[~]
└─$ awk '/MemTotal/ {total=$2} /MemFree/ {free=$2} END {print "fraction of free:",free/total}' /proc/meminfo
fraction of free: 0.889411

┌──(akhil㉿akhil)-[~]
└─$ ps -e |wc -l
20

┌──(akhil㉿akhil)-[~]
└─$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.1  0.3  23988 13664 ?        Ss   14:22   0:00 /sbin/init
root           2  0.0  0.0   3072  1664 ?        Sl   14:22   0:00 /init
root           6  0.0  0.0   3072  1792 ?        Sl   14:22   0:00 plan9 --control-socket 7 --log-level 4 --server-fd 8 --pip
root          43  0.0  0.4  50068 14976 ?        Ss   14:22   0:00 /usr/lib/systemd/systemd-journald
root          52  0.0  0.2  33616 10752 ?        Ss   14:22   0:00 /usr/lib/systemd/systemd-udevd
root         101  0.0  0.0   4280  2304 ?        Ss   14:22   0:00 /usr/sbin/cron -f
message+     104  0.0  0.0   7888  3456 ?        Ss   14:22   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork
root         113  0.0  0.2  17788  7936 ?        Ss   14:22   0:00 /usr/lib/systemd/systemd-logind
root         190  0.0  0.0   5168  2432 hvc0     Ss+  14:22   0:00 /usr/sbin/agetty --noreset --noclear --issue-file=/etc/iss
root         191  0.0  0.0   5124  2432 tty1     Ss+  14:22   0:00 /usr/sbin/agetty --noreset --noclear --issue-file=/etc/iss
root         418  0.0  0.0   3088   896 ?        Ss   14:22   0:00 /init
root         419  0.0  0.0   3088  1032 ?        S    14:22   0:00 /init
akhil        421  0.0  0.1   8548  5120 pts/0    Ss   14:22   0:00 -bash
root         427  0.0  0.1   7468  3840 ?        Ss   14:22   0:00 login -- akhil
akhil        433  0.0  0.3  21904 12288 ?        Ss   14:22   0:00 /usr/lib/systemd/systemd --user
akhil        435  0.0  0.0  22120  3652 ?        S    14:22   0:00 (sd-pam)
akhil        449  0.0  0.1   5308  4480 pts/1    Ss+  14:22   0:00 -bash
akhil        649  0.0  0.1   9340  3968 pts/0    R+   14:34   0:00 ps aux



┌──(akhil㉿akhil)-[~]
└─$ ps -eo stat | grep -c R
1

┌──(akhil㉿akhil)-[~]
└─$ ps -eo stat | grep -c D
0


┌──(akhil㉿akhil)-[~]
└─$ cat /proc/stat
cpu  268 595 13048 1097523 132 0 1852 0 0 0
cpu0 6 0 6128 84409 4 0 1778 0 0 0
cpu1 16 0 56 92889 17 0 56 0 0 0
cpu2 19 59 725 91981 34 0 8 0 0 0
cpu3 38 117 562 92118 16 0 0 0 0 0
cpu4 46 56 686 92003 20 0 0 0 0 0
cpu5 7 34 354 92500 1 0 1 0 0 0
cpu6 24 49 1070 91512 10 0 0 0 0 0
cpu7 10 45 610 92155 5 0 0 0 0 0
cpu8 52 56 811 91831 5 0 0 0 0 0
cpu9 21 67 830 91827 3 0 0 0 0 0
cpu10 18 56 657 92102 7 0 0 0 0 0
cpu11 8 51 556 92192 5 0 4 0 0 0
ctxt 11970644
btime 1779180722
processes 1063
procs_running 1
procs_blocked 0

┌──(akhil㉿akhil)-[~]
└─$ cat /proc/stat | grep 'processes'
processes 1074

┌──(akhil㉿akhil)-[~]
└─$ cat /proc/stat | grep 'ctxt'
ctxt 11973152