set_limit.c
changeset 60 47c13ca8c4d0
parent 51 a03372ef9714
child 77 49e0babccb23
equal deleted inserted replaced
59:a7ba10b68915 60:47c13ca8c4d0
     1 /**
     1 /**
     2  * test/demos/set_limit.c
     2  * test/demos/set_limit.c
     3  * Copyright (C) 2008 Markus Broeker
     3  * Copyright (C) 2008 Markus Broeker
     4  */
     4  */
     5 
     5 
     6 #include <sys/time.h>
     6 #include <errno.h>
     7 #include <sys/resource.h>
     7 #include <sys/resource.h>
       
     8 
       
     9 #define MINIMUM (2*1024*1024)
     8 
    10 
     9 int set_limit (int megs)
    11 int set_limit (int megs)
    10 {
    12 {
    11     struct rlimit rlim;
    13     struct rlimit rlim;
    12 
    14 
    13     megs *= 1024 * 1024;
    15     megs *= 1024 * 1024;
    14 
    16 
    15     rlim.rlim_cur = megs;
    17     rlim.rlim_cur = megs;
    16     rlim.rlim_max = 1.25 * megs;
    18     rlim.rlim_max = 1.25 * megs;
    17     if (megs > (4 * 1024 * 1024))
    19     if (megs >= MINIMUM)
    18         return setrlimit (RLIMIT_AS, &rlim);
    20         return setrlimit (RLIMIT_AS, &rlim);
       
    21 
       
    22     errno = ENOMEM;
    19 
    23 
    20     return -1;
    24     return -1;
    21 }
    25 }