Total memory used by Python process?

前端 未结 12 697
眼角桃花
眼角桃花 2020-11-22 04:28

Is there a way for a Python program to determine how much memory it\'s currently using? I\'ve seen discussions about memory usage for a single object, but what I need is tot

12条回答
  •  无人及你
    2020-11-22 04:49

    I like it, thank you for @bayer. I get a specific process count tool, now.

    # Megabyte.
    $ ps aux | grep python | awk '{sum=sum+$6}; END {print sum/1024 " MB"}'
    87.9492 MB
    
    # Byte.
    $ ps aux | grep python | awk '{sum=sum+$6}; END {print sum " KB"}'
    90064 KB
    

    Attach my process list.

    $ ps aux  | grep python
    root       943  0.0  0.1  53252  9524 ?        Ss   Aug19  52:01 /usr/bin/python /usr/local/bin/beaver -c /etc/beaver/beaver.conf -l /var/log/beaver.log -P /var/run/beaver.pid
    root       950  0.6  0.4 299680 34220 ?        Sl   Aug19 568:52 /usr/bin/python /usr/local/bin/beaver -c /etc/beaver/beaver.conf -l /var/log/beaver.log -P /var/run/beaver.pid
    root      3803  0.2  0.4 315692 36576 ?        S    12:43   0:54 /usr/bin/python /usr/local/bin/beaver -c /etc/beaver/beaver.conf -l /var/log/beaver.log -P /var/run/beaver.pid
    jonny    23325  0.0  0.1  47460  9076 pts/0    S+   17:40   0:00 python
    jonny    24651  0.0  0.0  13076   924 pts/4    S+   18:06   0:00 grep python
    

    Reference

    • memory - Linux: find out what process is using all the RAM? - Super User
    • Total memory used by Python process? - Stack Overflow
    • linux - ps aux output meaning - Super User

提交回复
热议问题