LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

getrlimit

resource limit query and management interface

TLDR

Get resource limits (shell)
$ ulimit -a
copy
Get specific limit (open files)
$ ulimit -n
copy
Show resource limits of a process
$ prlimit --pid [pid]
copy
Set open file limit for a command
$ prlimit --nofile=4096 [command]
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.

CONFIGURATION

/etc/security/limits.conf

PAM configuration for setting default resource limits per user or group.
/etc/systemd/system.conf
Systemd-wide default resource limits for services and user sessions.

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
Kai