#include <sys/resource.h> int getrlimit(int resource, struct rlimit *rlp);Service Program Name: QP0WSRV1
The getrlimit() function returns the resource limit for the specified resource. A resource limit is a way for the operating system to enforce a limit on a variety of resources used by a process. A resource limit is represented by a rlimit structure. The rlim_cur member specifies the current or soft limit and the rlim_max member specifies the maximum or hard limit.
The getrlimit() function supports the following resources:
RLIMIT_FSIZE (0) | The maximum size of a file in bytes that can be created by a process. |
RLIMIT_NOFILE (1) | The maximum number of file descriptors that can be opened by a process. |
RLIMIT_CORE (2) | The maximum size of a core file in bytes that can be created by a process. |
RLIMIT_CPU (3) | The maximum amount of CPU time in seconds that can be used by a process. |
RLIMIT_DATA (4) | The maximum size of a process' data segment in bytes. |
RLIMIT_STACK (5) | The maximum size of a process' stack in bytes. |
RLIMIT_AS (6) | The maximum size of a process' total available storage in bytes. |
The value of RLIM_INFINITY is considered to be larger than any other limit value. If the value of the limit is RLIM_INFINITY, then a limit is not enforced for that resource. The getrlimit() function always returns RLIM_INFINITY for the following resources: RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, and RLIMIT_STACK.
The resource to get the limits for.
Pointer to a struct rlim_t where the values of the hard and soft limits are returned.
None.
0 | getrlimit() was successful. |
-1 | getrlimit() was not successful. The errno variable is set to indicate the error. |
If getrlimit() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
The address used for an argument is not correct.
In attempting to use an argument in a call, the system detected an address that is not valid.
While attempting to access a parameter passed to this function, the system detected an address that is not valid.
An invalid parameter was found.
An invalid resource was specified.
See Code disclaimer information for information pertaining to code examples.
#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Set the file size resource limit. */ limit.rlim_cur = 65535; limit.rlim_max = 65535; if (setrlimit(RLIMIT_FSIZE, &limit) != 0) { printf("setrlimit() failed with errno=%d\n", errno); exit(1); } /* Get the file size resource limit. */ if (getrlimit(RLIMIT_FSIZE, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The soft limit is %llu\n", limit.rlim_cur); printf("The hard limit is %llu\n", limit.rlim_max); exit(0); }Example Output:
The soft limit is 65535 The hard limit is 65535
Top | UNIX-Type APIs | APIs by category |