HP-UX Reference (11i v2 03/08) - 2 System Calls (vol 5)

g
getrlimit(2) getrlimit(2)
NAME
getrlimit(), setrlimit() - control maximum resource consumption
SYNOPSIS
#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 resources by the calling process 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
represented by an rlimit structure, pointed to by the rlp argument and includes the following
members:
rlim_t rlim_cur; /* Current (soft) limit */
rlim_t rlim_max; /* Hard limit */
The
rlim_cur member specifies the current or soft limit and the
rlim_max member specifies the max-
imum 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 lim-
its can be changed in a single call to
setrlimit() subject to the constraints described above.
The value
RLIM_INFINITY, defined in
<sys/resource.h>, is considered to be larger than any other
limit value. If a call to
getrlimit() returns RLIM_INFINITY
for a resource, it means the implemen-
tation does not enforce limits on that resource. Specifying
RLIM_INFINITY
as any resource limit value
on a successful call to
setrlimit() inhibits enforcement of that resource limit.
The following resources are defined:
RLIMIT_CORE This is the maximum size of a core file in bytes that may be created by a pro-
cess. A limit of 0 will prevent the creation of a core file. If this limit is
exceeded, the writing of a core file will terminate at this size.
RLIMIT_CPU This is the maximum amount of CPU time in seconds allowed for a UNIX 95
conforming application. If this limit is exceeded, SIGXCPU is generated for
the application. The default action for a UNIX 95 conforming application is to
kill the process and leave a core file. If the process is blocking, catching or
ignoring SIGXCPU, the behavior is unspecified in UNIX 95 standard. The
HP-UX implementation blocks, catches or ignores
SIGXCPU as specified by
the UNIX 95 conforming applications. Be aware that an application designed
with the HP-UX behavior may not be portable if and when UNIX standards
define a different behavior. If the application is a Classic HP-UX application,
the kernel will not send the signal as a result of exceeding the CPU limit.
However, if this signal is sent explicitly to a Classic HP-UX application by
another application or via the
kill -XCPU command, this signal will be
delivered and the default action will be taken. In order for an application to
be UNIX 95, it must be linked with unix95.o either directly or indirectly.
For example:
% cc /usr/lib/unix95.o prog.c
Or,
% export UNIX95=1
% cc prog.c
RLIMIT_DATA This is the maximum size of a process data segment in bytes. If this limit is
exceeded, the brk(), malloc(), and sbrk() functions will fail with
errno set to ENOMEM. Attempts to set RLIMIT_DATA to
RLIM_INFINITY will always fail. The upper limit is enforced through the
tunable maxdsiz.
RLIMIT_FSIZE This option is only applicable to UNIX 95 conforming applications. Please see
RLIMIT_CPU option above for explanation on UNIX 95 conforming applica-
tions. This is the maximum size of a file in bytes that may be created by a
Section 2108 Hewlett-Packard Company 1 HP-UX 11i Version 2: August 2003