Find the answer to your Linux question:
Results 1 to 4 of 4
Hi Is there any mechanism in Linux where in I can specify the maximum heap which my program can use?...
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    5

    Restricting the heap usage of my program

    Hi

    Is there any mechanism in Linux where in I can specify the maximum heap which my program can use?

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    The closest thing I know to what you want is setrlimit()

  3. #3
    Just Joined!
    Join Date
    May 2007
    Posts
    5
    thanks for replying...
    i am trying to use this API but not getting how it will through the error.
    below is my code:
    Code:
    int main(int argc, char *argv[])
    {
               GdkPixbuf *pixbuf = NULL;
               GError *error = g_new(GError, 1);
    
               struct rlimit *value;
               getrlimit(RLIMIT_DATA, value);
               value->rlim_max = 1000000;
               setrlimit(RLIMIT_DATA, value);
    
               g_type_init();
               pixbuf = gdk_pixbuf_new_from_file("images.jpg", error);
               return 0; 
    }
    The code gives segmentation fault error once the execution of main is completed.
    Let me know is this is the correct way of using setrlimit();
    thanks

  4. #4
    Just Joined!
    Join Date
    May 2007
    Posts
    5
    the updated code is
    Code:
    int main(int argc, char *argv[])
    {
               GdkPixbuf *pixbuf = NULL;
               GError *error = g_new(GError, 1);
    
               struct rlimit value;
               value->rlim_cur = 0;
               value->rlim_max = 0;
               setrlimit(RLIMIT_DATA, &value);
    
               g_type_init();
               pixbuf = gdk_pixbuf_new_from_file("images.jpg", error);
               printf("errno = %d", errno);
               return 0; 
    }
    Now segmentation fault is not coming.
    But the thing is the code should print the value of errno as ENOMEM(12) but its printing 0.
    Please let me know the reason fo this ??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...