How do I find the maximum stack size?
Asked Answered
F

5

39

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?

Finnic answered 24/9, 2011 at 0:2 Comment(0)
S
32

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
Shingly answered 24/9, 2011 at 0:7 Comment(3)
I get a command not found error. What package do I need to install for this command?Finnic
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?Finnic
@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.Shingly
A
35

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

> ulimit -a         # shows the current stack size
Acosmism answered 24/9, 2011 at 0:8 Comment(3)
Of course, a quick google search now serves up this page.Interrelate
...and the link is dead. Also, it's ulimit -s to show the stack size.Malaco
Values are in kilobytes, except for -t, which is in seconds and -n and -u, which are unscaled values. -- man pagesCosma
S
32

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
Shingly answered 24/9, 2011 at 0:7 Comment(3)
I get a command not found error. What package do I need to install for this command?Finnic
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?Finnic
@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.Shingly
D
25

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

ulimit -s
Dorsey answered 9/10, 2014 at 11:57 Comment(0)
E
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.

Enidenigma answered 24/9, 2011 at 0:7 Comment(0)
D
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.

Dave answered 27/3, 2018 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.