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
-
37
-
6...and the link is dead. Also, it's
ulimit -s
to show the stack size. Commented Nov 14, 2022 at 10:45 -
Values are in kilobytes, except for -t, which is in seconds and -n and -u, which are unscaled values.
-- man pages– gmagnoCommented Feb 20 at 13:30
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
-
I get a command not found error. What package do I need to install for this command?– BruceCommented Sep 24, 2011 at 0: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?– BruceCommented Sep 24, 2011 at 0: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. Commented Sep 24, 2011 at 0:16
The following call to ulimit
returns the maximum stack size in kibibytes (210 = 1024 bytes):
ulimit -s
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.