6

Is there any way to find the starting and ending address of heap memory.

#include<stdio.h>
void main()
{
    printf("Ending address of Heap: %x\n",sbrk(0)); 
}

The above coding shows the ending address of heap memory. Like that is there any way to find the starting address of heap.

Output:

Ending address of Heap: 8556000

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
mohangraj
  • 9,842
  • 19
  • 59
  • 94
  • 1
    http://stackoverflow.com/questions/3565232/how-to-programmatically-get-the-address-of-the-heap-on-linux – udit043 Jul 06 '15 at 07:37

1 Answers1

2

On Linux you can open file /proc/self/maps, for example with fopen, and read it until you find line like this:

0060f000-00630000 rw-p 00000000 00:00 0 [heap]

0060f000-00630000 - address range of heap

fghj
  • 8,898
  • 4
  • 28
  • 56
  • In my system, the output is, 085a0000-085c1000 rw-p 00000000 00:00 0 [heap]. But, each time it will be changed. which means, at first time, the output is like this. At second time, the output is 0941b000-0943c000 rw-p 00000000 00:00 0 [heap]. But, what is my need is, at the time of program execution, the certain memory block is allocated to execute that program. So, that memory block is divided into text segment, data segment, heap and stack. So, how to find the start and ending address of heap memory for that program. – mohangraj Jul 06 '15 at 08:35
  • I suppose you have to turn off ASLR, to get the same results each time. https://en.wikipedia.org/wiki/Address_Space_Layout_Randomization – fghj Jul 18 '15 at 18:38