Heap memory

Submitted by jelari
on June 23, 2008 - 7:52am

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

strcmp
on
June 23, 2008 - 10:56am

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

Heap Mem

jelari
on
June 23, 2008 - 10:08pm

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

strcmp
on
June 23, 2008 - 10:16pm

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

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

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

sbrk()

strcmp
on
June 24, 2008 - 11:36am

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\]'

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

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

Could n't figure out

jelari
on
August 8, 2008 - 12: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

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

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.