Reputation: 21
I am creating a bunch of Python functions for use in a later script and they find things like free RAM, Total RAM, and RAM in use. I want to only find the number, nothing else. Is there a Python module or something to find only these numbers? I have tried psutil, but that is not what I want. I am using Linux, a terminal command would work as well. With your answer, please keep it simple, because I am a new programmer.
Upvotes: 1
Views: 538
Reputation: 567
You can use free
command with option -g
. This is will give a snapshot the memory in GB
[email protected].:~# free -g
total used free shared buffers cached
Mem: 31 24 6 0 0 14
-/+ buffers/cache: 10 21
Swap: 31 0 31
Upvotes: 0
Reputation: 22438
This will give you the total memory:
grep MemTotal /proc/meminfo |grep -oE "[0-9]*"
This one free memory:
grep MemFree /proc/meminfo |grep -oE "[0-9]*"
This one Active memory:
grep Active /proc/meminfo |grep -oE "[0-9]*"
You can extract all the information you need from /proc/meminfo like this.
To see what options do you have, run cat /proc/meminfo
Upvotes: 1