LinuxCommandLibrary

getrlimit

TLDR

Get resource limits (shell)

$ ulimit -a
copy
Get specific limit (shell)
$ ulimit -n
copy

SYNOPSIS

#include <sys/resource.h>
int getrlimit(int resource, struct rlimit \*rlim);
int setrlimit(int resource, const struct rlimit \*rlim);

DESCRIPTION

getrlimit() and setrlimit() are system calls for querying and setting resource limits for the calling process. These limits control maximum values for various system resources.
The ulimit shell built-in provides command-line access to these limits. Limits have soft (current) and hard (maximum) values.

PARAMETERS

resource

Resource type (RLIMITNOFILE, RLIMITNPROC, etc.).
rlim
Pointer to rlimit structure with soft/hard limits.

RESOURCES

$ RLIMIT_NOFILE  - Maximum open files
RLIMIT_NPROC   - Maximum processes
RLIMIT_AS      - Maximum address space
RLIMIT_CORE    - Maximum core file size
RLIMIT_STACK   - Maximum stack size
RLIMIT_DATA    - Maximum data segment
RLIMIT_FSIZE   - Maximum file size
RLIMIT_CPU     - CPU time limit
RLIMIT_MEMLOCK - Maximum locked memory
copy

SHELL ACCESS

$ ulimit -n        # Open files
ulimit -u        # Max processes
ulimit -s        # Stack size
ulimit -a        # All limits
ulimit -n 4096   # Set open files limit
copy

CAVEATS

System call, not a command. Non-root users cannot raise hard limits. Some limits affect child processes. PAM may set limits at login.

SEE ALSO

Copied to clipboard