11

I would like to know how to find the heap memory of a process that is running in the background. Is there any command that allows such?

tshepang
  • 64,472
  • 86
  • 223
  • 290
Tippu
  • 111
  • 1
  • 1
  • 3

1 Answers1

12

If you want to look at a particular process named e.g. wing_ide, then

ps a | fgrep wing_ide | fgrep -v fgrep

gives you a number at the beginning of the line (in my case 29837) use this number as follows:

fgrep '[heap]' /proc/29837/maps

The output look like:

01d56000-07026000 rw-p 00000000 00:00 0                       [heap]

If you do this on a regular basis you might want to use the following python program:

import sys
import psutil

for p in psutil.process_iter():
    if p.name == sys.argv[1]:
        print(pid)
        for map in p.get_memory_maps(grouped=False):
            if '[heap]' in map.path:
                print(map.addr)

To which program you provide the name of the process you want to search as an argument:

python findheap.py wing_ide
OverShifted
  • 105
  • 3
Anthon
  • 78,313
  • 42
  • 165
  • 222