prlimit
Set or get resource limits of a process
TLDR
Display limit values for all current resources for the running parent process
Display limit values for all current resources of a specified process
Run a command with a custom number of open files limit
SYNOPSIS
prlimit [options]
prlimit [options]
prlimit [options] --pid
prlimit [options]
PARAMETERS
-p, --pid
Specifies the process ID to query or modify. Required when operating on a running process.
-r, --resource
Specifies the resource limit to query or set. Common resources include nofile (open files), nproc (number of processes), cpu (CPU time), as (address space), core (core file size).
-s, --soft
Sets the soft limit for the specified resource. This is the current effective limit.
-h, --hard
Sets the hard limit for the specified resource. This is the ceiling that the soft limit cannot exceed.
-o, --output
Redirects output to a specified file instead of standard output.
-R, --raw
Displays output in raw format, without human-readable units.
--verbose
Provides more detailed output regarding the operation.
--version
Displays version information and exits.
--help
Displays a help message and exits.
DESCRIPTION
prlimit is a command-line utility used to query and set the resource limits of a running process or to apply limits to a command before its execution.
It provides a more versatile and direct way to manipulate resource limits compared to the shell built-in ulimit, as it can operate on a specific process ID (PID). Resource limits control the maximum amount of system resources a process can consume, such as CPU time, memory, open file descriptors, and number of processes.
These limits consist of a soft limit (current effective limit) and a hard limit (a ceiling that the soft limit cannot exceed). prlimit is invaluable for system administrators and developers to fine-tune system stability, prevent resource exhaustion by runaway processes, and manage system resources efficiently for specific applications. It is part of the util-linux package.
CAVEATS
Setting resource limits for a process requires appropriate permissions, typically root privileges, especially for increasing hard limits or modifying limits for processes owned by other users.
Hard limits can only be lowered by unprivileged users, not increased. Only the root user (or a process with CAP_SYS_RESOURCE capability) can increase hard limits.
Limits applied to a command using prlimit
RESOURCE NAMES AND UNITS
The
AS (address space): total address space in bytes.
CORE (core file size): maximum size of a core file in bytes.
CPU (CPU time): maximum CPU time in seconds.
DATA (data segment size): maximum size of the data segment in bytes.
FSIZE (file size): maximum size of files created in bytes.
LOCKS (locked locks): maximum number of file locks.
MEMLOCK (locked memory): maximum memory that can be locked in RAM in bytes.
MSGQUEUE (message queue size): maximum memory used by POSIX message queues in bytes.
NICE (nice value): maximum nice value (lower is higher priority).
NOFILE (open files): maximum number of open file descriptors.
NPROC (number of processes): maximum number of processes for the user.
RSS (resident set size): maximum resident set size in bytes.
RTPRIO (realtime priority): maximum realtime priority.
SIGPENDING (pending signals): maximum number of pending signals.
STACK (stack size): maximum stack size in bytes.
The special value unlimited (or -1) can be used for any resource to indicate no limit.
DISPLAYING AND SETTING LIMITS
When prlimit is run with only a PID (e.g., prlimit 12345), it displays all current soft and hard limits for that process in a human-readable format.
To set limits, specify the resource and optionally the soft and hard values. If only one value is given, it sets both soft and hard limits to that value. For example:
prlimit --pid 12345 --nofile 1024 sets both soft and hard nofile limits to 1024.
prlimit --pid 12345 --nofile 512:1024 sets soft to 512 and hard to 1024 for nofile.
HISTORY
prlimit is part of the util-linux project, a collection of essential system utilities for Linux. It was introduced to provide a more direct and flexible command-line interface to the setrlimit(2) and getrlimit(2) system calls, addressing some limitations and inconveniences of the older ulimit shell built-in. Its development aimed at offering better control over process resource limits, particularly for specific PIDs and for launching commands with predefined limits, contributing to better system resource management and stability.
SEE ALSO
ulimit(1), getrlimit(2), setrlimit(2), proc(5)