Reputation: 21
I am trying to identify any way if we can increase the stack size of my running program after getting SIGSEGV. I know we can increase the size of stack by ulimit -c but, that did not solve this problem. Because my process is already dead. I want to handle this situation where my process will not get killed even after segfault. setrlimit() is one way which can be used for exceed stack size statically. But I don't want to block more memory than I need.
Upvotes: 2
Views: 1777
Reputation: 144550
Under Linux, setting a higher limit for the stack size does not commit this memory to your process. The memory will be paged in as required.
The default stack size in quite large already. You should run under the debugger or produce a core upon SIGSEGV to analyze what is really going on. You might have a very deep recursion, or an inordinate amount of local variable space, possibly via VLAs allocated by mistake. Increasing the stack space may hide the problem for a while, but it is not a reliable solution.
Upvotes: 3
Reputation: 12262
A recent OS will not automatically reserve the memory for the stack, but just add pages as required. The ulimit is just an upper bound you allow it to use up. So increasing the stack size statically should be no problem and exactly what you want.
Upvotes: 1