User avatar
Alex_Landherr
Posts: 281
Joined: Mon May 18, 2020 3:14 pm
Location: Sweden
Contact: Twitter

How to Get Total Amount of Bytes of Memory on Current System? [SOLVED]

Thu Oct 14, 2021 9:19 am

I need help with finding how to get a value that is the total number of bytes of system RAM, used and free. Is there something similar to disk_usage in shutil?
Last edited by Alex_Landherr on Fri Oct 15, 2021 11:25 am, edited 1 time in total.
Helpful answers are appreciated.
I usually respond to Tweets directed at me.

3D Printer: Original Prusa Mini+

OS:
  • Raspberry Pi OS
  • Windows 10
Programming Languages:
  1. Python
  2. Java

User avatar
kerry_s
Posts: 2440
Joined: Thu Jan 30, 2020 7:14 pm

Re: How to Get Total Amount of Bytes of Memory on Current System?

Thu Oct 14, 2021 9:25 am

man free or free --help

free -b
free -t

User avatar
Alex_Landherr
Posts: 281
Joined: Mon May 18, 2020 3:14 pm
Location: Sweden
Contact: Twitter

Re: How to Get Total Amount of Bytes of Memory on Current System?

Thu Oct 14, 2021 9:43 am

So nothing in Python?
Helpful answers are appreciated.
I usually respond to Tweets directed at me.

3D Printer: Original Prusa Mini+

OS:
  • Raspberry Pi OS
  • Windows 10
Programming Languages:
  1. Python
  2. Java

User avatar
thagrol
Posts: 5839
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: How to Get Total Amount of Bytes of Memory on Current System?

Thu Oct 14, 2021 11:56 am

Alex_Landherr wrote:
Thu Oct 14, 2021 9:43 am
So nothing in Python?
Tre investigating the sys module. That may have something.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

scotty101
Posts: 4300
Joined: Fri Jun 08, 2012 6:03 pm

Re: How to Get Total Amount of Bytes of Memory on Current System?

Thu Oct 14, 2021 12:05 pm

psutil seems to be the go to module for this type of thing

https://github.com/giampaolo/psutil
https://psutil.readthedocs.io/en/latest/#memory

Code: Select all

>>> psutil.virtual_memory()
svmem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, active=4748992512, inactive=2758115328, buffers=790724608, cached=3500347392, shared=787554304)
>>> psutil.swap_memory()
sswap(total=2097147904, used=296128512, free=1801019392, percent=14.1, sin=304193536, sout=677842944)
>>>
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Python”