41

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?

0

5 Answers 5

36

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

> ulimit -a         # shows the current stack size
3
  • 37
    Of course, a quick google search now serves up this page.
    – gerardw
    Commented May 22, 2017 at 19:03
  • 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
    – gmagno
    Commented Feb 20 at 13:30
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
3
  • I get a command not found error. What package do I need to install for this command?
    – Bruce
    Commented 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?
    – Bruce
    Commented 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
26

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

ulimit -s
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.

0
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.