Nov
6

how to increase stack size in linux.

Author saurabh    Category Uncategorized     Tags

Normally you would set the stack size early on, e,g, at the start of main(), before calling any other functions. Typically the logic would be:

  • call getrlimit to get current stack size
  • if current size < required stack size then
    • call setrlimit to increase stack size to required size

In C that might be coded something like this:

#include <sys/resource.h>
 
int main (int argc, char **argv)
{
    const rlim_t kStackSize = 64L * 1024L * 1024L;   // min stack size = 64 Mb
    struct rlimit rl;
    int result;
 
    result = getrlimit(RLIMIT_STACK, &rl);
    if (result == 0)
    {
        if (rl.rlim_cur < kStackSize)
        {
            rl.rlim_cur = kStackSize;
            result = setrlimit(RLIMIT_STACK, &rl);
            if (result != 0)
            {
                fprintf(stderr, "setrlimit returned result = %d\n", result);
            }
        }
    }
 
    // ...
 
    return 0;
}

 

saurabh

hey friends i have completed my B.Tech in CE from Ganpat University & now i am working as Android Middleware & Application Developer in one Private firm. i really enjoy programming...!!

Facebook - More Posts

You may like to read this also....

2 Comments to “how to increase stack size in linux.”

  • jigar November 19, 2011 at 5:57 am

    buddy stack size also can be increaese by this way

    gcc -Wl,–stack,16777216 -o file.exe file.c

    no need to do this all stuff in code…!!
    jigar recently posted..how to increase stack size in linux.My Profile

    • saurabh November 19, 2011 at 6:00 am

      Its Programmatic Way

Post comment

CommentLuv badge
Follow us on Twitter! Follow us on Twitter!

Search in this website

our sponsors

our sponsors

latest post

latest comments

Find us on Facebook

tag cloud

Top Authors

saurabh
17 posts
16 posts
4 posts

Find us on stackoverflow

Polls

Tell us who you are

View Results

Loading ... Loading ...

Categories