What is the relationship between ulimit -s
On UNIX/Linux, getrlimit(RLIMIT_STACK) is only guaranteed to give the size of the main thread's stack. The OpenGroup's reference is explicit on that, "initial thread's stack":
http://www.opengroup.org/onlinepubs/009695399/functions/getrlimit.html
For Linux, there's a reference which indicates that RLIMIT_STACK is what will be used by default for any thread stack (for NPTL threading):
http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_create.3.html
Generally, since the programmer can decide (by using nonstandard attributes when creating the thread) where to put the stack and/or how much stack to use for a new thread, there is no such thing as a "cumulative process stack limit". It rather comes out of the total RLIMIT_AS address space size.
But you do have a limit on the number of threads you can create,sysconf(PTHREAD_THREADS_MAX), and you do have a lower limit for the minimum size a thread stack must have,sysconf(PTHREAD_STACK_MIN).
Also, you can query the default stacksize for new threads:
pthread_attr_t attr;
size_t stacksize;
if (!pthread_attr_init(&attr) && !pthread_attr_getstacksize(&attr, &stacksize))
printf("default stacksize for a new thread: %ld\n", stacksize);
I.e. default-initialize a set of pthread attributes and ask for what stacksize the system gave you.
In a threaded program, stacks for all threads (except the initial one) are allocated out of the heap, so RLIMIT_STACK has little or no relation to how much stack space you can use for your threads.