Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Linux Stack?

I recently ran into a bug with the "linux stack" and the "linux stack size". I came across a blog directing me to try

ulimit -a

to see what the limit for my box was, and it was set to 8192kb which seems to be the default.

What is the "linux stack"? How does it work, what does it store, what does it do?

like image 330
jaredonline Avatar asked Jan 18 '12 04:01

jaredonline


People also ask

What is stack and heap in Linux?

The heap is where all user-allocated memory is located. The heap grows up from a lower memory address to a higher memory address. Stack—whenever a program makes a function call, the current function's state needs to be saved onto the stack. The stack grows down from a higher memory address to a lower memory address.

What is Linux stack limit?

On Linux/x86-32, the default stack size for a new thread is 2 megabytes. Under the NPTL threading implementation, if the RLIMIT_STACK soft resource limit at the time the program started has any value other than "unlimited", then it determines the default stack size of new threads.

What is stack overflow Linux?

A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.

Is Linux an OS or kernel?

Linux is an open source operating system that is made up of the kernel, the base component of the OS, and the tools, apps, and services bundled along with it.


1 Answers

The short answer is:

When programs on your linux box run, they add and remove data from the stack on a regular basis as the programs function. The stack size, referes to how much space is allocated in memory for the stack. If you increase the stack size, that allows the program to increase the number of routines that can be called. Each time a function is called, data can be added to the stack (stacked on top of the last routines data.)

Unless the program is a very complex, or designed for a special purpose, a stack size of 8192kb is normally fine. Some programs like graphics processing programs require you to increase the size of the stack to function. As they may store a lot of data on the stack.

Feel free to increase the stack size for those applications, its not a problem. To do so, use

ulimit -s bytes

BTW, What is a StackOverflowError?

like image 158
nycynik Avatar answered Sep 22 '22 15:09

nycynik