GETRLIMIT(3)               POSIX Programmer's Manual              GETRLIMIT(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       getrlimit, setrlimit -- control maximum resource consumption

SSYYNNOOPPSSIISS
       #include <sys/resource.h>

       int getrlimit(int _r_e_s_o_u_r_c_e, struct rlimit *_r_l_p);
       int setrlimit(int _r_e_s_o_u_r_c_e, const struct rlimit *_r_l_p);

DDEESSCCRRIIPPTTIIOONN
       The _g_e_t_r_l_i_m_i_t() function shall get, and the _s_e_t_r_l_i_m_i_t() function shall
       set, limits on the consumption of a variety of resources.

       Each call to either _g_e_t_r_l_i_m_i_t() or _s_e_t_r_l_i_m_i_t() identifies a specific
       resource to be operated upon as well as a resource limit. A resource
       limit is represented by an rrlliimmiitt structure. The _r_l_i_m___c_u_r member
       specifies the current or soft limit and the _r_l_i_m___m_a_x member specifies
       the maximum or 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 appropriate privileges
       can raise a hard limit. Both hard and soft limits can be changed in a
       single call to _s_e_t_r_l_i_m_i_t() subject to the constraints described above.

       The value RLIM_INFINITY, defined in _<_s_y_s_/_r_e_s_o_u_r_c_e_._h_>, shall be
       considered to be larger than any other limit value. If a call to
       _g_e_t_r_l_i_m_i_t() returns RLIM_INFINITY for a resource, it means the
       implementation shall not enforce limits on that resource. Specifying
       RLIM_INFINITY as any resource limit value on a successful call to
       _s_e_t_r_l_i_m_i_t() shall inhibit enforcement of that resource limit.

       The following resources are defined:

       RLIMIT_CORE   This is the maximum size of a ccoorree file, in bytes, that
                     may be created by a process. A limit of 0 shall prevent
                     the creation of a ccoorree file. If this limit is exceeded,
                     the writing of a ccoorree file shall terminate at this size.

       RLIMIT_CPU    This is the maximum amount of CPU time, in seconds, used
                     by a process.  If this limit is exceeded, SIGXCPU shall
                     be generated for the process. If the process is catching
                     or ignoring SIGXCPU, or all threads belonging to that
                     process are blocking SIGXCPU, the behavior is
                     unspecified.

       RLIMIT_DATA   This is the maximum size of a data segment of the
                     process, in bytes.  If this limit is exceeded, the
                     _m_a_l_l_o_c() function shall fail with _e_r_r_n_o set to [[EENNOOMMEEMM]].

       RLIMIT_FSIZE  This is the maximum size of a file, in bytes, that may be
                     created by a process. If a write or truncate operation
                     would cause this limit to be exceeded, SIGXFSZ shall be
                     generated for the thread. If the thread is blocking, or
                     the process is catching or ignoring SIGXFSZ, continued
                     attempts to increase the size of a file from end-of-file
                     to beyond the limit shall fail with _e_r_r_n_o set to [[EEFFBBIIGG]].

       RLIMIT_NOFILE This is a number one greater than the maximum value that
                     the system may assign to a newly-created descriptor. If
                     this limit is exceeded, functions that allocate a file
                     descriptor shall fail with _e_r_r_n_o set to [[EEMMFFIILLEE]].  This
                     limit constrains the number of file descriptors that a
                     process may allocate.

       RLIMIT_STACK  This is the maximum size of the initial thread's stack,
                     in bytes. The implementation does not automatically grow
                     the stack beyond this limit. If this limit is exceeded,
                     SIGSEGV shall be generated for the thread. If the thread
                     is blocking SIGSEGV, or the process is ignoring or
                     catching SIGSEGV and has not made arrangements to use an
                     alternate stack, the disposition of SIGSEGV shall be set
                     to SIG_DFL before it is generated.

       RLIMIT_AS     This is the maximum size of total available memory of the
                     process, in bytes. If this limit is exceeded, the
                     _m_a_l_l_o_c() and _m_m_a_p() functions shall fail with _e_r_r_n_o set
                     to [[EENNOOMMEEMM]].  In addition, the automatic stack growth
                     fails with the effects outlined above.

       When using the _g_e_t_r_l_i_m_i_t() function, if a resource limit can be
       represented correctly in an object of type rrlliimm__tt, then its
       representation is returned; otherwise, if the value of the resource
       limit is equal to that of the corresponding saved hard limit, the value
       returned shall be RLIM_SAVED_MAX; otherwise, the value returned shall
       be RLIM_SAVED_CUR.

       When using the _s_e_t_r_l_i_m_i_t() function, if the requested new limit is
       RLIM_INFINITY, the new limit shall be ``no limit''; otherwise, if the
       requested new limit is RLIM_SAVED_MAX, the new limit shall be the
       corresponding saved hard limit; otherwise, if the requested new limit
       is RLIM_SAVED_CUR, the new limit shall be the corresponding saved soft
       limit; otherwise, the new limit shall be the requested value. In
       addition, if the corresponding saved limit can be represented correctly
       in an object of type rrlliimm__tt then it shall be overwritten with the new
       limit.

       The result of setting a limit to RLIM_SAVED_MAX or RLIM_SAVED_CUR is
       unspecified unless a previous call to _g_e_t_r_l_i_m_i_t() returned that value
       as the soft or hard limit for the corresponding resource limit.

       The determination of whether a limit can be correctly represented in an
       object of type rrlliimm__tt is implementation-defined. For example, some
       implementations permit a limit whose value is greater than
       RLIM_INFINITY and others do not.

       The _e_x_e_c family of functions shall cause resource limits to be saved.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _g_e_t_r_l_i_m_i_t() and _s_e_t_r_l_i_m_i_t() shall return 0.
       Otherwise, these functions shall return -1 and set _e_r_r_n_o to indicate
       the error.

EERRRROORRSS
       The _g_e_t_r_l_i_m_i_t() and _s_e_t_r_l_i_m_i_t() functions shall fail if:

       EEIINNVVAALL An invalid _r_e_s_o_u_r_c_e was specified; or in a _s_e_t_r_l_i_m_i_t() call, the
              new _r_l_i_m___c_u_r exceeds the new _r_l_i_m___m_a_x.

       EEPPEERRMM  The limit specified to _s_e_t_r_l_i_m_i_t() would have raised the maximum
              limit value, and the calling process does not have appropriate
              privileges.

       The _s_e_t_r_l_i_m_i_t() function may fail if:

       EEIINNVVAALL The limit specified cannot be lowered because current usage is
              already higher than the limit.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       If a process attempts to set the hard limit or soft limit for
       RLIMIT_NOFILE to less than the value of {_POSIX_OPEN_MAX} from
       _<_l_i_m_i_t_s_._h_>, unexpected behavior may occur.

       If a process attempts to set the hard limit or soft limit for
       RLIMIT_NOFILE to less than the highest currently open file descriptor
       +1, unexpected behavior may occur.

RRAATTIIOONNAALLEE
       It should be noted that RLIMIT_STACK applies ``at least'' to the stack
       of the initial thread in the process, and not to the sum of all the
       stacks in the process, as that would be very limiting unless the value
       is so big as to provide no value at all with a single thread.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _e_x_e_c, _f_o_r_k(), _m_a_l_l_o_c(), _o_p_e_n(), _s_i_g_a_l_t_s_t_a_c_k(), _s_y_s_c_o_n_f(), _u_l_i_m_i_t()

       The Base Definitions volume of POSIX.1-2017, <<ssttrrooppttss..hh>>,
       <<ssyyss__rreessoouurrccee..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                         GETRLIMIT(3)
