?
Solved

Stack and heap size of a running program

Posted on 2005-04-05
7
Medium Priority
?
616 Views
Last Modified: 2012-08-14
How to find the stack and heap size of a running program in Linux and Solaris?

Thanks
Ram
0
Comment
Question by:ram_nambiar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:_corey_
ID: 13707991
ulimit -a

will give you the stack size limits.

corey
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 13708331
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
 
LVL 8

Expert Comment

by:_corey_
ID: 13708350
Quite so, I mis-assumed he wanted to know what sizes they were given.

corey
0
 
LVL 22

Accepted Solution

by:
NovaDenizen earned 500 total points
ID: 13709059
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
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 500 total points
ID: 13744206
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question