0

I'm making a Operating System in Python at the moment, just as a little project.

However; I need it to print at the start of the code how much memory is available on the host system.

I have looked this up and despite reading through walls of text, I am still unable to find anything. I have not yet attempted to compose anything because I wouldn't know where to start. I am a beginner and am relatively new to Python, so please excuse me if I sound a bit dumb.

Any suggestion or code is welcome. Thanks.

Mac
  • 1
  • 2

1 Answers1

1

Assuming your question is about RAM, you can simply use the psutil package.

In this example I created a simple function memory_available():

import psutil
from psutil._common import bytes2human

def memory_available():
    # Get total physical memory expressed in bytes
    total_phy_memory = psutil.virtual_memory().total

    # Convert to a more readable format
    total_phy_memory_GB = bytes2human(total_phy_memory)

    # Return total physical memory expressed in gigabytes
    return total_phy_memory_GB

print(memory_available())

The psutil package is a:

Cross-platform lib for process and system monitoring in Python.

While bytes2human converts to a more readable format. In this case, Gigabytes.

stardust
  • 177
  • 2
  • 9
whoisraibolt
  • 2,082
  • 3
  • 22
  • 45
  • If the answer solves your problem or you believe it is the best solution. Please, up-vote and mark this answer as accepted! Thank you! If it doesn't solve your problem, let me know! – whoisraibolt Jun 02 '21 at 00:10