On Linux and Unix systems there are many ways of finding system details and current system stats.
so of the most commonly used commands are TOP,freemem, free etc but there is another way to find this information. Actually, you can pull this information from the exact place the commands above pull it from.
enter the /proc directory this directory holds files that reside in memory they are dynamic files that exist when the system is running and system information. located here you will find details about PID ( Process Id) as well as system stats information lets take a look at how to find memory information.
First, of call lets list the contents of this folder,
if you see below we have files name cpuinfo,meminfo,iomem etc.
sean@MANCINI-EXT:/proc$ ls
1 16 18828 22 298 42 82 asound diskstats ioports kpageflags pagetypeinfo sys vmstat
10 160 18829 23 299 5 83 buddyinfo dma irq loadavg partitions sysrq-trigger zoneinfo
11 167 18835 24 3 7 84 bus driver kallsyms locks sched_debug sysvipc
12 17 18836 25 302 75 86 cgroups execdomains kcore meminfo schedstat thread-self
13 18 18845 26 303 77 87 cmdline fb keys misc self timer_list
134 18789 19 27 335 78 9 consoles filesystems key-users modules slabinfo tty
135 18816 196 28 341 79 90 cpuinfo fs kmsg mounts softirqs uptime
14 18821 2 29 357 8 9131 crypto interrupts kpagecgroup mtrr stat version
15 18825 21 290 41 80 acpi devices iomem kpagecount net swaps vmallocinfo
sean@MANCINI-EXT:/proc$
these files have corresponding information lets cat the meminfo file
if you see below we see details about the current memory stats such as physical memory and available memory if you run the free command that command will pull the information from this file.
sean@MANCINI-EXT:/proc$ cat meminfo
MemTotal: 1020364 kB
MemFree: 680872 kB
MemAvailable: 828160 kB
Buffers: 67936 kB
Cached: 206576 kB
SwapCached: 0 kB
Active: 186676 kB
Inactive: 110260 kB
Active(anon): 22624 kB
Inactive(anon): 10384 kB
Active(file): 164052 kB
Inactive(file): 99876 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 1046524 kB
SwapFree: 1046524 kB
Dirty: 24 kB
Writeback: 0 kB
AnonPages: 22428 kB
Mapped: 20808 kB
Shmem: 10588 kB
now if you notice if you do an ls -lah in this folder you will see something interesting
Notice how all of the files sizes are 0 this is because this is a virtual file system these files don’t actually exist and are not written to disk they reside in memory
-r–r–r– 1 root root 0 Jul 11 11:21 dma
dr-xr-xr-x 2 root root 0 Jul 11 11:21 driver
-r–r–r– 1 root root 0 Jul 11 11:21 execdomains
-r–r–r– 1 root root 0 Jul 11 11:21 fb
-r–r–r– 1 root root 0 Jul 11 11:21 filesystems
dr-xr-xr-x 5 root root 0 Jul 1 14:27 fs
-r–r–r– 1 root root 0 Jul 11 11:21 interrupts
-r–r–r– 1 root root 0 Jul 11 11:21 iomem
-r–r–r– 1 root root 0 Jul 11 11:21 ioports
dr-xr-xr-x 21 root root 0 Jul 1 14:27 irq
-r–r–r– 1 root root 0 Jul 11 11:21 kallsyms
-r——– 1 root root 128T Jul 11 11:21 kcore
-r–r–r– 1 root root 0 Jul 11 11:21 keys
-r–r–r– 1 root root 0 Jul 11 11:21 key-users
-r——– 1 root root 0 Jul 1 14:27 kmsg
-r——– 1 root root 0 Jul 11 11:21 kpagecgroup
-r——– 1 root root 0 Jul 11 11:21 kpagecount
-r——– 1 root root 0 Jul 11 11:21 kpageflags
-r–r–r– 1 root root 0 Jul 11 11:21 loadavg
-r–r–r– 1 root root 0 Jul 11 11:21 locks
-r–r–r– 1 root root 0 Jul 11 11:21 meminfo
-r–r–r– 1 root root 0 Jul 11 11:21 misc
-r–r–r– 1 root root 0 Jul 11 11:21 modules
let’s see what we can find when you cd into a pid folder in the /proc folder
in this folder, for pid2 you will see data for this pid one of them is the io file
attr cmdline environ io mem ns pagemap schedstat stat timers
autogroup comm exe limits mountinfo numa_maps personality sessionid statm timerslack_ns
auxv coredump_filter fd loginuid mounts oom_adj projid_map setgroups status uid_map
cgroup cpuset fdinfo map_files mountstats oom_score root smaps syscall wchan
clear_refs cwd gid_map maps net oom_score_adj sched stack task
sean@MANCINI-EXT:/proc/2$
from this file, you can see how much io this process is taking at this time
sudo cat io
rchar: 0
wchar: 0
syscr: 0
syscw: 0
read_bytes: 0
write_bytes: 0
cancelled_write_bytes: 0
sean@MANCINI-EXT:/proc/2$
the /proc directory can be very useful for system administrators to investigate problems with performance and even check the reason a PID may be hanging by checking the details of the process
Please let me know if you want to know more about the /proc directory