How to monitor memory usage within Python? (Linux)

Giampaolo Rodola' gnewsg at gmail.com
Thu Feb 25 08:15:04 EST 2010


On 24 Feb, 23:35, kj <no.em... at please.post> wrote:
> Is there some standard module for getting info about the process's
> memory usage, in a Linux/Unix system?
>
> (I want to avoid hacks that involve, e.g., scraping ps's output.)
>
> Thanks!
>
> ~K

http://code.google.com/p/psutil

>>> import psutil
>>> p = psutil.Process(7055)
>>> p.cmdline
['/usr/bin/python']
>>> rss, vms =  p.get_memory_info()
>>> "Resident memory: %s KB" %(rss / 1024)
'Resident memory: 3768 KB'
>>> "Virtual memory: %s KB" %(vms / 1024)
'Virtual memory: 6176 KB'
>>> p.get_memory_percent()
0.8342


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/



More information about the Python-list mailing list