Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

csh(1)

sigvec(2)

sigstack(2)

GETRLIMIT(2)                         BSD                          GETRLIMIT(2)



NAME
     getrlimit, setrlimit - control maximum system resource consumption

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

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

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

DESCRIPTION
     Limits on the consumption of system resources by the current process and
     each process it creates may be obtained with the getrlimit call and set
     with the setrlimit call.

     The resource parameter is one of the following:

     RLIMIT_CPU       Maximum amount of CPU time (in milliseconds) to be used
                      by each process.  A Domain/OS BSD process will receive a
                      SIGXCPU signal when its CPU usage reaches RLIMIT_CPU.

     RLIMIT_FSIZE     Largest size, in bytes, of any single file that can be
                      created.

     RLIMIT_DATA      Maximum size, in bytes, of the data segment for a
                      process; this defines how far a program may extend its
                      break with the sbrk(2) system call.

     RLIMIT_STACK     Maximum size, in bytes, of the stack segment for child
                      processes; this defines the size of a program's stack
                      segment.

     RLIMIT_CORE      Largest size, in bytes, of a core file that can be
                      created.  Since Domain/OS BSD doesn't create core
                      images, it doesn't implement this parameter.

     RLIMIT_RSS       Maximum size, in bytes, to which a process' resident set
                      size can grow.  This imposes a limit on the amount of
                      physical memory to be given to a process; if memory is
                      tight, the system will prefer to take memory from
                      processes that are exceeding their declared resident set
                      size.  In Domain/OS BSD, calls to setrlimit specifying
                      RLIMIT_RSS have no other effect than saving the value
                      specified.  Calls to getrlimit simply return the value
                      saved.

     The above parameters impose operational limits on a process.  If it
     exceeds a limit (the CPU time, for example), a process may receive a
     signal.  Processes can change these "soft" limits within the hard limits
     imposed by the system.

     The rlimit structure is used to specify the hard and soft limits on a
     resource:

          struct rlimit {
               int  rlim_cur; /* current (soft) limit */
               int  rlim_max; /* hard limit */
          };

     Only the super-user may raise the maximum limits.  Other users may only
     alter rlim_cur within the range from 0 to rlim_max or (irreversibly)
     lower rlim_max.

     An "infinite" value for a limit is defined as RLIM_INFINITY (0x7FFFFFFF).

     Because this information is stored in the per-process information, this
     system call must be executed directly by the shell if it is to affect all
     future processes created by the shell; limit is thus a built-in command
     to csh(1).

     The system refuses to extend the data or stack space when the limits
     would be exceeded in the normal way: a break call fails if the data space
     limit is reached.  When the stack limit is reached, the process receives
     a segmentation fault (SIGSEGV). If this signal is not caught by a handler
     using the signal stack, this signal will kill the process.

     A file I/O operation that would create a file that is too large will
     cause a signal SIGXFSZ to be generated; this normally terminates the
     process, but may be caught.  When the soft CPU time limit is exceeded, a
     signal SIGXCPU is sent to the offending process.

ERRORS
     The possible errors are:

     [EFAULT]   The address specified for rlp is invalid.

     [EPERM]    The limit specified to setrlimit would have raised the maximum
                limit value, and the caller is not the super-user.

SEE ALSO
     csh(1), sigvec(2), sigstack(2)

DIAGNOSTICS
     A successful call returns 0.  A failed call returns -1 and sets errno to
     indicate the error.

NOTES
     There should be limit and unlimit commands in sh(1) as well as in csh.

     Some UNIX implementations define RLIMIT_STACK to be the maximum size, in
     bytes, of the stack segment for a process.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026