How to monitor memory usage within Python? (Linux)

Discussion in 'Python' started by kj, Feb 24, 2010.

  1. kj

    kj Guest

    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
     
    kj, Feb 24, 2010
    #1
    1. Advertising

  2. kj

    MrJean1 Guest

    For Linux only

    <http://code.activestate.com/recipes/286222/>

    /Jean

    On Feb 24, 2:35 pm, kj <> 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
     
    MrJean1, Feb 25, 2010
    #2
    1. Advertising

  3. On 24 Feb, 23:35, kj <> 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/
     
    Giampaolo Rodola', Feb 25, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. metfan
    Replies:
    2
    Views:
    4,852
    Robert Olofsson
    Oct 21, 2003
  2. hvt
    Replies:
    0
    Views:
    1,212
  3. hvt
    Replies:
    0
    Views:
    1,475
  4. ScottZ
    Replies:
    2
    Views:
    361
    Jorgen Grahn
    Nov 2, 2008
  5. Krist
    Replies:
    8
    Views:
    6,487
    Arne Vajhøj
    Feb 10, 2010
Loading...

Share This Page