rlimit: Resource Limits

rlimitR Documentation

Resource Limits

Description

Get and set process resource limits. Each function returns the current limits, and can optionally update the limit by passing argument values. The rlimit_all() function is a convenience wrapper which prints all current hard and soft limits.

Usage

rlimit_all()

rlimit_as(cur = NULL, max = NULL)

rlimit_core(cur = NULL, max = NULL)

rlimit_cpu(cur = NULL, max = NULL)

rlimit_data(cur = NULL, max = NULL)

rlimit_fsize(cur = NULL, max = NULL)

rlimit_memlock(cur = NULL, max = NULL)

rlimit_nofile(cur = NULL, max = NULL)

rlimit_nproc(cur = NULL, max = NULL)

rlimit_stack(cur = NULL, max = NULL)

Arguments

cur

set the current (soft) limit for this resource. See details.

max

set the max (hard) limit for this resource. See details.

Details

Each resource has an associated soft and hard limit. The soft limit is the value that the kernel enforces for the corresponding resource. The hard limit acts as a ceiling for the soft limit: an unprivileged process may set only its soft limit to a value in the range from 0 up to the hard limit, and (irreversibly) lower its hard limit.

Definitons from the Linux manual page are as follows:

  • RLIMIT_AS : the maximum size of the process's virtual memory (address space) in bytes.

  • RLIMIT_CORE : the maximum size of a core file that the process may dump.

  • RLIMIT_CPU : a limit in seconds on the amount of CPU time (not elapsed time) that the process may consume. When the process reaches the soft limit, it is sent a SIGXCPU signal.

  • RLIMIT_DATA : the maximum size of the process's data segment (initialized data, uninitialized data, and heap).

  • RLIMIT_FSIZE : the maximum size of files that the process may create. Attempts to extend a file beyond this limit result in delivery of a SIGXFSZ signal.

  • RLIMIT_MEMLOCK : the maximum number of bytes of memory that may be locked into RAM.

  • RLIMIT_NOFILE : a value one greater than the maximum file descriptor number that can be opened by this process.

  • RLIMIT_NPROC : the maximum number of processes that can be created for the real user ID of the calling process. Upon encountering this limit, fork fails with the error EAGAIN. Not enforced for root user.

  • RLIMIT_STACK : the maximum size of the process stack, in bytes.

Note that the support for enforcing limits very widely by system. In particular RLIMIT_AS has a different meaning depending on how memory allocation is managed by the operating system (and doesn't work at all on MacOS).

References

GETRLIMIT(2)

Examples

# Print all limits
rlimit_all()

# Get one limit
rlimit_as()

## Not run: 
# Set a soft limit
lim <- rlimit_as(1e9)
print(lim)

# Reset the limit to max
rlimit_as(cur = lim$max)

# Set a hard limit (irreversible)
rlimit_as(max = 1e10)

## End(Not run)

jeroen/unix documentation built on Feb. 22, 2024, 12:52 p.m.