1GETRLIMIT(2)               Linux Programmer's Manual              GETRLIMIT(2)
2
3
4

NAME

6       getrlimit, setrlimit - get/set resource limits
7

SYNOPSIS

9       #include <sys/time.h>
10       #include <sys/resource.h>
11
12       int getrlimit(int resource, struct rlimit *rlim);
13       int setrlimit(int resource, const struct rlimit *rlim);
14

DESCRIPTION

16       getrlimit()  and  setrlimit() get and set resource limits respectively.
17       Each resource has an associated soft and hard limit, as defined by  the
18       rlimit  structure  (the  rlim  argument  to  both getrlimit() and setr‐
19       limit()):
20
21            struct rlimit {
22                rlim_t rlim_cur;  /* Soft limit */
23                rlim_t rlim_max;  /* Hard limit (ceiling for rlim_cur) */
24            };
25
26       The soft limit is the value that the kernel  enforces  for  the  corre‐
27       sponding  resource.   The  hard  limit  acts  as a ceiling for the soft
28       limit: an unprivileged process may only set its soft limit to  a  value
29       in  the range from 0 up to the hard limit, and (irreversibly) lower its
30       hard  limit.   A  privileged  process  (under  Linux:  one   with   the
31       CAP_SYS_RESOURCE capability) may make arbitrary changes to either limit
32       value.
33
34       The value RLIM_INFINITY denotes no limit on a  resource  (both  in  the
35       structure  returned by getrlimit() and in the structure passed to setr‐
36       limit()).
37
38       resource must be one of:
39
40       RLIMIT_AS
41              The maximum size of the process's virtual memory (address space)
42              in  bytes.   This  limit  affects  calls  to brk(2), mmap(2) and
43              mremap(2), which fail with the error ENOMEM upon exceeding  this
44              limit.  Also automatic stack expansion will fail (and generate a
45              SIGSEGV that kills the process if no alternate  stack  has  been
46              made  available via sigaltstack(2)).  Since the value is a long,
47              on machines with a 32-bit long either this limit is  at  most  2
48              GiB, or this resource is unlimited.
49
50       RLIMIT_CORE
51              Maximum  size  of  core file. When 0 no core dump files are cre‐
52              ated.  When non-zero, larger dumps are truncated to this size.
53
54       RLIMIT_CPU
55              CPU time limit in seconds.  When the process  reaches  the  soft
56              limit, it is sent a SIGXCPU signal.  The default action for this
57              signal is to terminate the process.  However, the signal can  be
58              caught,  and the handler can return control to the main program.
59              If the process continues to consume CPU time, it  will  be  sent
60              SIGXCPU  once  per  second  until  the hard limit is reached, at
61              which time it is sent SIGKILL.   (This  latter  point  describes
62              Linux  2.2  through  2.6 behaviour.  Implementations vary in how
63              they treat processes which continue to consume  CPU  time  after
64              reaching  the  soft  limit.   Portable applications that need to
65              catch this si