Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I type ulimit -s in terminal it shows 8192. Does it mean that in my C code I could only have local variable of 8192 bytes?

I am confused which stack size. Does ulimit -s change when we modify its value?

share|improve this question
up vote 5 down vote accepted

First of all, it is 8192 kilo bytes, and not bytes. Furthermore stack is one thing, variable is another, and heap yet another. See this explanation of differences between stack and heap, for example, or this page. As far as I know stack is used for local and short lived variables, and it depends on the compiler whether stack or heap are used.

As far as I can tell, if you use [mc]alloc and friends to allocate memory, you are not touching upon the stack, and the limits do not hold.

But yes, trying the following at ulimit -s equal to 8192 will result in a segmentation fault:

#include <stdlib.h>

int main() {
  char foo[10000000] ;
  foo[0] = 'a' ;
  exit( 0 ) ;

Here, the variable foo is too large.

$ gcc test.c
$ ./a.out
Segmentation fault (core dumped)

However, if you change the ulimit (e.g. ulimit -s 16000), it will work.

share|improve this answer
How do I know my stack size limit? I mean, which is the maximum number I can write afer ulimit -s? – markk borras Nov 21 '15 at 10:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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