• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Stack and heap size of a running program

How to find the stack and heap size of a running program in Linux and Solaris?

Thanks
Ram
0
ram_nambiar
Asked:
ram_nambiar
  • 2
  • 2
2 Solutions
 
_corey_Commented:
ulimit -a

will give you the stack size limits.

corey
0
 
NovaDenizenCommented:
ulimit only prints out the limits; not the actual size of a running process.

I think you will find the pmap program useful.  It produces output like:
 $ pmap 2635
2635:   -/bin/bash
08048000    592K r-x--  /bash
080dc000     24K rw---  /bash
080e2000    148K rwx--    [ anon ]
40000000     84K r-x--  /ld-2.3.4.so
40015000      4K rw---    [ anon ]
40016000      8K rw---  /ld-2.3.4.so
40018000      8K rw---    [ anon ]
4001b000      8K r-x--  /libdl-2.3.4.so
4001d000      8K rw---  /libdl-2.3.4.so
4001f000   1088K r-x--  /libc-2.3.4.so
4012f000      4K -----  /libc-2.3.4.so
40130000      4K r----  /libc-2.3.4.so
40131000     12K rw---  /libc-2.3.4.so
40134000      8K rw---    [ anon ]
40136000     28K r-x--  /libnss_compat-2.3.4.so
4013d000      8K rw---  /libnss_compat-2.3.4.so
4013f000     68K r-x--  /libnsl-2.3.4.so
40150000      8K rw---  /libnsl-2.3.4.so
40152000      8K rw---    [ anon ]
40154000     32K r-x--  /libnss_nis-2.3.4.so
4015c000      8K rw---  /libnss_nis-2.3.4.so
4015e000     32K r-x--  /libnss_files-2.3.4.so
40166000      8K rw---  /libnss_files-2.3.4.so
bfffa000     24K rwx--    [ stack ]
 total     2224K
 $

The "[ stack ]" line shows you the size of the stack.  
All of the 40xxxxxx entries represent dynamic libraries mmap'ed into the process space.
I believe the "080e2000    148K rwx--    [ anon ]" line represents the heap.
I think the first two "bash" entries represent the segments of the /bin/bash binary.

0
 
_corey_Commented:
Quite so, I mis-assumed he wanted to know what sizes they were given.

corey
0
 
NovaDenizenCommented:
I ran pmap on another process, and it turns out there can be entries explicitly marked with "[ heap ]".  The solaris and linux versions of pmap are a little different, and I haven't been able to find detailed information about either.  
0
 
stefan73Commented:
Hi NovaDenizen,
The entire ptools use the /proc pseudo-FS. I once wrote a pmap-like utility as part of a Solaris binary monitor in Perl. I don't have it here; I just remember there's one include file which defines the structures of the pmap output. Basically, there's one structure entry for each printed pmap line.

The source of both Linux and Solaris pmap are available on the Web.

Cheers!

Stefan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now