I wanted to write a script to check my RAM usage at regular intervals and then calculate its maximum.
To calculate the used Memory, I had two options, via neofetch
or free -m
The output of $ free -m
gives:
total used free shared buff/cache available
Mem: 15839 4169 7630 794 4039 10555
Swap: 2047 0 2047
So, I piped the output as $ free -m | grep Mem | awk '{print ($3/1024)}'
which results in 4.07324
.
Now, if I do something similar to $neofetch
output as, $ neofetch | grep -i Memory | awk '{print ($2/1024)}'
, I get the output as 4.84668
Thus, these 2 outputs do not match up, which one is to be considered for checking the actual RAM usage?
If it matters, I have a 4gb GTX1650 running Nvidia drivers, and consuming 53MB
RAM when checked via $ nvidia-smi
One of the possible situations I can think of, is where $ neofetch
gives me the Used memory and the shared memory, since the outputs of
$ free -m | grep Mem | awk '{print (($3+$5)/1024)}'
and
$ neofetch | grep -i Memory | awk '{print ($2/1024)}'
are very close to each other (4.85547
and 4.86035
)
But my question remains, which memory values to trust?