getrlimit(), getrlimit64()
Get the limit on a system resource
Synopsis:
#include <sys/resource.h>
int getrlimit( int resource,
               struct rlimit * rlp );
int getrlimit64( int resource,
                 struct rlimit64 * rlp );
Arguments:
- resource
 - The resource whose limit you want to get; one of the following:
  
- RLIMIT_AS
 - RLIMIT_CHANNELS_NP
 - RLIMIT_CORE
 - RLIMIT_CPU
 - RLIMIT_DATA
 - RLIMIT_FREEMEM
 - RLIMIT_FSIZE
 - RLIMIT_MQUEUE_NUM_NP
 - RLIMIT_MQUEUE_SIZE_NP
 - RLIMIT_NOCONN_NP
 - RLIMIT_NOFILE
 - RLIMIT_NPROC
 - RLIMIT_NTHR
 - RLIMIT_OFILE
 - RLIMIT_RSS
 - RLIMIT_SHM_HANDLES_NP
 - RLIMIT_SIGEVENT_NP
 - RLIMIT_STACK
 - RLIMIT_TIMERS_NP
 - RLIMIT_VMEM
 
For descriptions and the actions taken when the current limit is exceeded, see prlimit().
 - rlp
 - A pointer to an rlimit or rlimit64
  structure where the function can store the limit on the resource.
  The rlimit and rlimit64 structures
  include at least the following members:
rlim_t rlim_cur; /* current (soft) limit */ rlim_t rlim_max; /* hard limit */The rlim_t type is an arithmetic data type to which you can cast objects of type int, size_t, and off_t without loss of information.
 
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The getrlimit() and getrlimit64() functions get the limits on the consumption of various system resources by a process and each process it creates.
Classificationin
What's in a Function Description?.
Each call to getrlimit() 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. The call to getrlimit() in turn calls prlimit() with the new_rlp argument set to NULL.
For information on how to change limit values, refer to the description of setrlimit() or prlimit().
Returns:
- 0
 - Success.
 - -1
 - An error occurred (errno is set).
 
Errors:
- EFAULT
 - The rlp argument points to an illegal address.
 - EINVAL
 - An invalid resource was specified.
 
Examples:
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
int main( void )
{
    struct rlimit curr_limits;
    
    if (getrlimit (RLIMIT_NPROC, &curr_limits) == -1) {
        perror ("The call to getrlimit() failed.");
        return EXIT_FAILURE;
    } else {
        printf ("The current maximum number of processes is %d.\n",
               (int) curr_limits.rlim_cur);
        printf ("The hard limit on the number of processes is %d.\n",
               (int) curr_limits.rlim_max);
    }
        return EXIT_SUCCESS;
}
Classification:
getrlimit() is POSIX 1003.1; getrlimit64() is Large-file support
| Safety: | |
|---|---|
| Cancellation point | No | 
| Signal handler | Yes | 
| Thread | Yes | 
