peter
peter

Reputation: 11

total memory used by running python code

I am running python program using Linux operating system and i want to know how much total memory used for this process. Is there any way to determine the total memory usage ?

Upvotes: 0

Views: 521

Answers (3)

nick_gabpe
nick_gabpe

Reputation: 5765

You can use psutil module. It can be installed with sudo pip install psutil

import os, psutil
process = psutil.Process(os.getpid())
print process.memory_info().rss

This is crossplaform method.

Upvotes: 1

Organis
Organis

Reputation: 7316

If you are looking for a python way to do it:

import os

# obtain the current process id
pid = str(os.getpid())

# read the process system status
status = os.system('cat /proc/' + pid + '/status')

print status

Upvotes: 2

WholesomeGhost
WholesomeGhost

Reputation: 1121

You can just open task manager and look how much ram does it take. I use Ubuntu and it came preinstalled.

Upvotes: 0

Related Questions