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?
5 Answers
A quick Google search should reveal some information on this subject.
> ulimit -a # shows the current stack size

- 1,270
- 2
- 13
- 16
-
32Of course, a quick google search now serves up this page. – gerardw May 22 '17 at 19:03
-
3...and the link is dead. Also, it's `ulimit -s` to show the stack size. – user2023370 Nov 14 '22 at 10:45
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

- 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
The following call to ulimit
returns the maximum stack size in kibibytes (210 = 1024 bytes):
ulimit -s

- 1,293
- 10
- 26

- 17,118
- 7
- 88
- 91
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.
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.

- 2,711
- 7
- 28
- 32

- 41
- 1