LinuxCommandLibrary

prlimit

Set or get resource limits of a process

TLDR

Display limit values for all current resources for the running parent process

$ prlimit
copy

Display limit values for all current resources of a specified process
$ prlimit [[-p|--pid]] [pid_number]
copy

Run a command with a custom number of open files limit
$ prlimit [[-n|--nofile=]][10] [command]
copy

SYNOPSIS

prlimit [options] [--pid pid] command [arguments]
prlimit [options] --pid pid

PARAMETERS

--resource=resource
    Specify the resource to limit. Common resources include: cpu (CPU time), fsize (file size), data (data segment size), stack (stack size), core (core file size), rss (resident set size), nofile (number of open files), nproc (number of processes), memlock (locked-in-memory size), as (address space), locks (file locks), sigpending (pending signals), msgqueue (message queue bytes), nice (nice value), rtprio (real-time priority), and rttime (real-time timeout). Omitted to show all resources.

--pid=pid
    Apply the limit to the process with the specified PID. If not provided, prlimit executes the provided command (and arguments) as a child process with the specified limits.

--soft=limit
    Set the soft limit for the specified resource.

--hard=limit
    Set the hard limit for the specified resource.

--=limit
    Shorthand for setting both soft and hard limits on a particular resource. This option overrides both --soft and --hard.

--version
    Display version information and exit.

--help
    Display help text and exit.

DESCRIPTION

The prlimit command is a powerful utility used to both retrieve and modify the resource limits of a running process, or of a process that will be executed. Resource limits, such as the maximum CPU time a process can use or the maximum amount of memory it can allocate, are important for system stability and security. prlimit allows administrators and developers to control resource consumption, preventing runaway processes from consuming excessive resources and impacting other processes or the system as a whole.
It retrieves or sets the soft and hard limits on various resources for a process identified by its PID (Process ID) or a command about to be executed. This command provides fine-grained control over resource allocation, ensuring efficient system utilization and improved application stability.

CAVEATS

The user needs sufficient privileges to modify limits of other processes. Setting limits too low can prevent processes from functioning correctly.

LIMIT VALUES

Limits can be expressed as numeric values (e.g., 1024 for kilobytes, 1048576 for megabytes), or using special keywords: 'unlimited' indicates no limit, and 'default' restores the system's default limit.

EXAMPLE USAGES

To show limits for PID 1234:
prlimit --pid 1234
To set CPU limit to 10 seconds for a command:
prlimit --cpu=10 command
To set both soft and hard limits for memory:
prlimit --memlock=1024 command

HISTORY

prlimit was introduced in the util-linux package. It enhances the functionality of the older ulimit command by allowing limits to be set for processes other than the shell itself, improving process management and system security. prlimit has become a standard tool for system administrators and developers for managing resource allocation.

SEE ALSO

getrlimit(2), setrlimit(2), ulimit(1)

Copied to clipboard