36

I am working on Ubuntu 11.04. How do I find out the maximum call stack size of a process and also the size of each frame of the stack?

Bruce
  • 33,927
  • 76
  • 174
  • 262

5 Answers5

32

A quick Google search should reveal some information on this subject.

> ulimit -a         # shows the current stack size
fruchtose
  • 1,270
  • 2
  • 13
  • 16
31

You can query the maximum process and stack sizes using getrlimit. Stack frames don't have a fixed size; it depends on how much local data (i.e., local variables) each frame needs.

To do this on the command-line, you can use ulimit.

If you want to read these values for a running process, I don't know of any tool that does this, but it's easy enough to query the /proc filesystem:

cat /proc/<pid>/limits
Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • I get a command not found error. What package do I need to install for this command? – Bruce Sep 24 '11 at 00:08
  • They need to have some starting size right? Does the compiler calculate beforehand the size of stack frame (taking into account all the local variables) and then allocate the frame? – Bruce Sep 24 '11 at 00:10
  • 1
    @Bruce: Yes, it's largely up to the compiler how stack frames are laid out and sized. "Creating" a frame is as simple as adjusting the stack pointer to leave enough room for the called function to carry out its business. Also, calls to `alloca()` (and maybe others) can grow the frame dynamically. – Marcelo Cantos Sep 24 '11 at 00:16
24

The following call to ulimit returns the maximum stack size in kibibytes (210 = 1024 bytes):

ulimit -s
Bernardo Sulzbach
  • 1,293
  • 10
  • 26
cprcrack
  • 17,118
  • 7
  • 88
  • 91
5

You can use getrlimit to see the stack size and setrlimit to change it.

There's an example in the Increase stack size in Linux with setrlimit post.

Community
  • 1
  • 1
sashang
  • 11,704
  • 6
  • 44
  • 58
4

getrlimit() and setrlimit() are not Linux commands. They are system calls.

So in order to get the result of them, you need something like a bash script or any other executable script that returns the result of the system call.

Yoh Deadfall
  • 2,711
  • 7
  • 28
  • 32