Tim Uglow ,Engineer, Sun.

more about setting the stack_size rlimit in a running process

Several folks have asked when should a program set the stack size rlimit.. just before exec() is the only sensible point.

Once your process has started up things have been mapped just below the reserved stack space, the size of which is the value of the stack space resource limit at the time the program assembled its address space ( ie during exec).

So if I use setrlimit to change the current stack space setting to a bigger number
then all future mappings will be pushed down below that reserved space but existing mappings won't
move, and if your stack tries to grow over them you will get a segv signal. So you should only ever increase the stack size rlimit just before a call to exec().

This stack size will only affect the default stack for the main thread in a process, the stack for
other threads are sized at thread_create() time either using the default 1MB or a program specified amount.