Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to increase the stack size/recursion limit?

I'm writing a C program and am exceeding the recursion limit via a segmentation fault. Is there any way to increase the program's recursion limit (perhaps via increasing the stack size), either via an option to GCC or via a command-line option? The program is running on Ubunutu.

like image 551
Claudiu Avatar asked Jan 23 '15 22:01

Claudiu


2 Answers

You can change the stack size with ulimit on Linux, for example:

ulimit -s unlimited

On Windows with Visual Studio, use /F option.

like image 143
ouah Avatar answered Oct 22 '22 04:10

ouah


The stack size is a function of the operating system, though many earlier operating systems (MSDOS for example) didn't do program stack segment control: it was up to the program to reserve an adequately sized segment.

With virtual memory and 32-bit APIs, the stack size is usually provided by a resource management mechanism. For example, on Linux, the ulimit command provides one source of stack size control. Other levels of control are provided by mechanisms inside the kernel enforcing system policy, memory limitations, and other limits.

like image 27
wallyk Avatar answered Oct 22 '22 05:10

wallyk