Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the starting and ending address of Heap memory for a program?

Tags:

c

linux

unix

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

like image 409
mohangraj Avatar asked Nov 09 '22 09:11

mohangraj


1 Answers

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

like image 139
fghj Avatar answered Nov 14 '22 23:11

fghj