prlimit Command Linux: Complete Guide to Display and Set Process Resource Limits

August 25, 2025

The prlimit command is a powerful Linux utility that allows system administrators and users to view and modify resource limits for running processes. Unlike the traditional ulimit command that only works with the current shell, prlimit can manipulate limits for any process by its PID (Process ID).

Understanding Process Resource Limits

Process resource limits are constraints imposed by the operating system to prevent individual processes from consuming excessive system resources. These limits help maintain system stability and ensure fair resource distribution among processes.

Linux supports two types of limits:

  • Soft Limit: The current effective limit that can be increased up to the hard limit
  • Hard Limit: The maximum value that the soft limit can reach

prlimit Command Syntax

The basic syntax of the prlimit command is:

prlimit [options] [--resource[=limits]] [--pid PID | command [arguments]]

Common Options

  • --pid: Specify the process ID to modify
  • --output: Define output format
  • --verbose: Enable verbose output
  • --noheadings: Don’t print column headings

Displaying Current Process Limits

To view all resource limits for the current process, simply run:

$ prlimit

Sample output:

RESOURCE   DESCRIPTION                             SOFT      HARD      UNITS
AS         address space limit                unlimited unlimited bytes
CORE       max core file size                         0 unlimited bytes
CPU        CPU time                           unlimited unlimited seconds
DATA       max data size                      unlimited unlimited bytes
FSIZE      max file size                      unlimited unlimited bytes
LOCKS      max number of file locks held      unlimited unlimited locks
MEMLOCK    max locked-in-memory address space     65536     65536 bytes
MSGQUEUE   max bytes in POSIX mqueues            819200    819200 bytes
NICE       max nice prio allowed to raise             0         0
NOFILE     max number of open files                1024      4096 files
NPROC      max number of processes                 4096      4096 processes
RSS        max resident set size             unlimited unlimited bytes
RTPRIO     max real-time priority                     0         0
RTTIME     timeout for real-time tasks       unlimited unlimited microseconds
SIGPENDING max number of pending signals           4096      4096 signals
STACK      max stack size                       8388608 unlimited bytes

Viewing Limits for Specific Processes

To check limits for a specific process using its PID:

$ prlimit --pid 1234

You can also use process names with pgrep:

$ prlimit --pid $(pgrep firefox)

Setting Resource Limits

Setting Limits for New Processes

To start a new process with specific limits:

$ prlimit --nofile=1024:2048 --nproc=100:200 firefox

This command starts Firefox with:

  • Maximum open files: 1024 (soft), 2048 (hard)
  • Maximum processes: 100 (soft), 200 (hard)

Modifying Limits for Running Processes

To modify limits for an existing process:

$ sudo prlimit --pid 1234 --nofile=2048:4096

Note: Root privileges are typically required to modify limits for other users’ processes.

Common Resource Types

File-Related Limits

Resource Description Example
NOFILE Maximum number of open files --nofile=1024:2048
FSIZE Maximum file size --fsize=1G:2G
LOCKS Maximum file locks --locks=100:200

Memory-Related Limits

Resource Description Example
AS Virtual memory size --as=1G:2G
RSS Resident set size --rss=512M:1G
STACK Stack size --stack=8M:16M
DATA Data segment size --data=1G:2G

Process-Related Limits

Resource Description Example
NPROC Maximum processes --nproc=100:200
CPU CPU time in seconds --cpu=3600:7200
RTTIME Real-time CPU time --rttime=1000000

Practical Examples

Example 1: Limiting Memory Usage

Start a process with limited virtual memory:

$ prlimit --as=512M:1G python memory_intensive_script.py

Example 2: Controlling File Access

Run a web server with limited file descriptors:

$ prlimit --nofile=1000:2000 --nproc=50:100 httpd

Example 3: CPU Time Restriction

Limit CPU time for a computation:

$ prlimit --cpu=600:600 ./compute_task

This allows exactly 10 minutes (600 seconds) of CPU time.

Advanced Usage Scenarios

Monitoring Resource Usage

Create a monitoring script to check if processes are approaching their limits:

#!/bin/bash
for pid in $(pgrep firefox); do
    echo "Process $pid limits:"
    prlimit --pid $pid --output RESOURCE,SOFT,HARD,UNITS
    echo "---"
done

Setting Temporary Limits

Apply temporary limits without modifying system configuration:

$ prlimit --nofile=500:1000 --nproc=10:20 bash -c 'your_command_here'

Understanding Limit Inheritance

Child processes inherit resource limits from their parent processes. This means:

  • Processes started from a shell inherit the shell’s limits
  • System services inherit limits from their parent (usually systemd)
  • Modified limits apply to the target process and its children

Common Use Cases

Database Servers

Database servers often need increased file descriptor limits:

$ sudo prlimit --pid $(pgrep mysqld) --nofile=65536:65536

Web Servers

Web servers may require process and connection limits:

$ prlimit --nproc=1000:2000 --nofile=8192:16384 nginx

Development Environment

Limit resource usage for testing:

$ prlimit --as=256M:512M --cpu=300:300 ./test_application

Error Handling and Troubleshooting

Permission Denied

If you encounter permission errors:

$ sudo prlimit --pid 1234 --nofile=2048:4096

Invalid Limit Values

Ensure soft limits don’t exceed hard limits:

# Incorrect - soft limit exceeds hard limit
$ prlimit --nofile=2048:1024 command

# Correct
$ prlimit --nofile=1024:2048 command

Integration with System Services

For systemd services, you can set limits in service files:

[Service]
LimitNOFILE=4096
LimitNPROC=2048
ExecStart=/path/to/your/service

Then use prlimit to verify the applied limits:

$ prlimit --pid $(systemctl show --property MainPID --value your-service)

Best Practices

  • Monitor regularly: Check resource usage patterns before setting limits
  • Test thoroughly: Verify that applications work correctly with imposed limits
  • Document changes: Keep records of limit modifications for troubleshooting
  • Use conservative values: Start with generous limits and tighten gradually
  • Consider system resources: Ensure total limits don’t exceed system capacity

Comparison with Related Commands

Command Scope Modification Target
ulimit Current shell Current session Shell and children
prlimit Any process Runtime modification Specific PID
systemd limits Services Service configuration System services

Conclusion

The prlimit command is an essential tool for Linux system administration, offering granular control over process resource consumption. By understanding its syntax, options, and practical applications, you can effectively manage system resources, prevent resource exhaustion, and maintain optimal system performance.

Whether you’re managing server applications, developing software, or troubleshooting performance issues, mastering prlimit will enhance your ability to control and optimize Linux system behavior. Remember to always test limit changes in non-production environments and monitor their effects on application performance.