1

I am seeing a difference of behavior when setting stack size from shell and from inside my c program. The issue is that I have a function which has a large set of local variables (large arrays).

If I do the following

limit stack 256000

my c program goes on without failure But the same value from inside crashes at function invocation

The first few lines of main , before the function is invoked are as follows -

struct rlimit lim = {256000*1024, 256000*1024};
int x=setrlimit(RLIMIT_STACK, &lim);
if(x!=0) {
    printf("Error in setrlimit);
}

There is no error issued by setrlimit.

Adding to this, it seems it is specific to certain platforms (SuSE 11) and does not happen across all oses.

How can I ensure that the stack size increased by my program is effective ?Another thing is that even if I put huge values in setrlimit ,there is no effect.

  • oops ! my bad, I had shortened the code for the question. It was a typing mistake. Have put the original code now. – amisax Jan 19 '17 at 8:23
0

the way setrlimit(RLIMIT_STACK) gets applied is platform specific and diverges broadly.

if what you want is to make sure that the limit gets increased for your process, the best way is to set it in the shell before your process gets started (as you pointed out in your question), since then it will get applied regardless of if your process is threaded or not or what are the specifics of the implementation your platform abides for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.