login
Header Space

 
 

Heap memory

June 23, 2008 - 10:52am
Submitted by jelari on June 23, 2008 - 10:52am.
Linux

Hi all,
How can i determine how much heap space is allocated for a particular process?
Is there any configuration file that i can look at?

Regards
-Jelari-

ulimit

June 23, 2008 - 1:56pm

look at ulimit, enter ulimit -a to see current settings

Heap Mem

June 24, 2008 - 1:08am

No, I just want to know how much of heap memory is allocated for a particular process?.. Is there any command through which i can figure out with pid.

-Happy Coding -
Regards,
Jelari.

ps

June 24, 2008 - 1:16am

ps can do that. as a start try "ps l" and then examine the "format specifiers".

if you want to be non-portable, you can also consult /proc/<pid>/status and proc/<pid>/maps.

I think brk() system call

June 24, 2008 - 8:32am
matt_kleviar (not verified)

I think brk() system call gives you current heapsize.

sbrk()

June 24, 2008 - 2:36pm

brk() returns 0 on success or -1 on error. you can use the derived library function sbrk() to get the current program break (i.e. heap end pointer) (call sbrk(0)), but you then have to find out the start pointer... and it is perfectly possible to allocate heap memory without moving the program break (using mmap() with flags MAP_ANONYMOUS|MAP_PRIVATE).

grep '\[heap\]'

June 24, 2008 - 3:53pm
Anonymous (not verified)

grep '\[heap\]' /proc/1234567/maps

Could n't figure out

August 8, 2008 - 3:27am

#include
#include
main ()
{
char *a;
a = malloc (100);
while (1);

}

#grep '\[heap\]' /proc/maps

I could not able to differentiate the heap size if the size of allocation is changed to 10 or 20. the maps shows the same memory difference.

-Happy Coding -
Regards,
Jelari.

Glibc will reserve heap for

August 9, 2008 - 6:26pm
Anonymous (not verified)

Glibc will reserve heap for itself. A malloc does not necessarily influence the size of the heap as seen from the kernel.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
speck-geostationary