Amiga Unix — 68040 · 68060

Manual pages › System calls (2)

getrlimit(2)

control maximum system resource consumption

From the original Amiga UNIX 2.1 manual. Some things it mentions may not be in this release.

NAME

getrlimit, setrlimit - control maximum system resource consumption

SYNOPSIS

#include <sys/time.h>
#include <sys/resource.h>

int getrlimit(int resource, struct rlimit *rlp);
int setrlimit(int resource, const struct rlimit *rlp);

DESCRIPTION

Limits on the consumption of a variety of  system  resources
by  a  process  and  each process it creates may be obtained
with getrlimit and set with setrlimit.  Each call to  either
getrlimit  or setrlimit identifies a specific resource to be
operated upon as well as a resource limit.  A resource limit
is  a  pair  of  values:   one specifying the current (soft)
limit, the other a maximum (hard) limit.  Soft limits may be
changed by a process to any value that is less than or equal
to the hard limit.  A process may (irreversibly)  lower  its
hard limit to any value that is greater than or equal to the
soft limit.  Only a process with an  effective  user  ID  or
superuser can raise a hard limit.  Both hard and soft limits
can be changed in a single call to setrlimit subject to  the
constraints  described  above.   Limits may have an infinite
value of RLIM_INFINITY.  rlp is a pointer to  struct  rlimit
that includes the following members:

     rlim_t rlim_cur; /* current (soft) limit */
     rlim_t rlim_max; /* hard limit */
rlim_t is an arithmetic data type to which objects  of  type
int,  size_t, and off_t can be cast without loss of informa-
tion.  The possible resources, their descriptions,  and  the
actions taken when current limit is exceeded, are summarized
in the table below:
_Resources______Description_________Action_____
RLIMIT_CORE   The     maximum   The writing  of
              size  of a core   a   core   file
              file  in  bytes   will  terminate
              that   may   be   at this size.
              created  by   a
              process.      A
              limit of 0 will
              prevent     the
              creation  of  a
              core file.

RLIMIT_CPU    The     maximum   SIGXCPU is sent
              amount  of  CPU   to the process.
              time in seconds   If the  process
              used  by a pro-   is  holding  or
              cess.             ignoring
                                SIGXCPU,    the
                                behavior     is
                                scheduling
                                class defined.

RLIMIT_DATA   The     maximum   brk(2)     will
              size    of    a   fail with errno
              process's  heap   set to ENOMEM.
              in bytes.
__Resources_______Description__________Action_____
RLIMIT_FSIZE    The     maximum   SIGXFSZ is sent
                size  of a file   to the process.
                in  bytes  that   If the  process
                may  be created   is  holding  or
                by  a  process.   ignoring
                A  limit  of  0   SIGXFSZ,   con-
                will    prevent   tinued attempts
                the creation of   to increase the
                a file.           size of a  file
                                  beyond      the
                                  limit will fail
                                  with  errno set
                                  to EFBIG.

RLIMIT_NOFILE   The     maximum   Functions  that
                number  of open   create new file
                file   descrip-   descriptors
                tors  that  the   will  fail with
                process     can   errno  set   to
                have.             EMFILE.

RLIMIT_STACK    The     maximum   SIGSEGV is sent
                size    of    a   to the process.
                process's stack   If the  process
                in  bytes.  The   is  holding  or
                system will not   ignoring   SIG-
                automatically     SEGV,   or   is
                grow the  stack   catching   SIG-
                beyond     this   SEGV   and  has
                limit.            not        made
                                  arrangements to
                                  use  an  alter-
                                  nate stack [see
                                  sigaltstack(2)],
                                  the disposition
                                  of SIGSEGV will
                                  be    set    to
                                  SIG_DFL  before
                                  it is sent.

RLIMIT_VMEM     The     maximum   brk(2)      and
                size    of    a   mmap(2)   func-
                process's         tions will fail
                mapped  address   with  errno set
                space in bytes.   to ENOMEM.   In
                                  addition,   the
                                  automatic stack
                                  growth     will
                                  fail  with  the
                                  effects    out-
                                  lined above.
Because limit  information  is  stored  in  the  per-process
information,  the shell builtin ulimit must directly execute
this system call if it is to  affect  all  future  processes
created by the shell.  The value of the current limit of the
following resources affect these implementation defined con-
stants:
      Limit___________Implementation_Defined_Constant
      RLIMIT_FSIZE    FCHR_MAX
      RLIMIT_NOFILE   OPEN_MAX

RETURN VALUE

Upon successful completion, the function getrlimit returns a
value  of  0;  otherwise,  it returns a value of -1 and sets
errno to indicate an error.

ERRORS

Under the following conditions, the functions getrlimit  and
setrlimit fail and set errno to:

EINVAL if  an  invalid  resource  was  specified;  or  in  a
       setrlimit  call,  the  new  rlim_cur  exceeds the new
       rlim_max.

EPERM  if the limit specified to setrlimit would have raised
       the  maximum  limit  value,  and  the  caller  is the
       superuser

SEE ALSO

malloc(3C), open(2), sigaltstack(2), signal(5).