ulimit - macOS
Overview
ulimit is a command-line utility used to control the resource limits for processes on macOS. It allows administrators to set limits on various resources, such as the maximum file size, the number of open files, and the amount of memory that can be used.
Syntax
ulimit [-H|-h] [-acdeflmnpstu] [-S segment-limit] [-t time-limit] [-v memory-limit] [-i pid]
Options/Flags
- -a: Display all current limits.
- -c: Set the maximum core file size.
- -d: Set the maximum data segment size.
- -e: Set the maximum stack size.
- -f: Set the maximum open file descriptors.
- -H, -h: Display a help message.
- -l: Set the maximum locked-in-memory address space.
- -m: Set the maximum resident set size.
- -n: Set the maximum number of simultaneously open files.
- -p: Set the maximum pipe size.
- -S: Set the maximum segment size.
- -s: Set the maximum stack size.
- -t: Set the maximum CPU time per process.
- -u: Set the maximum number of processes per user.
- -v: Set the maximum virtual memory size.
- -i pid: Set limits for a specific process using its PID.
Examples
Display all current limits:
ulimit -a
Set the maximum number of open files to 2048:
ulimit -n 2048
Set the maximum memory limit for a process with PID 1234 to 1 GB:
ulimit -v 1024 -i 1234
Common Issues
- Permission denied: Ensure that you have sufficient permissions to modify resource limits.
- Invalid argument: Verify that the provided arguments are valid and match the expected format.
- Resource limit unavailable: Some limits may not be adjustable due to system constraints.
Integration
ulimit can be integrated with other commands to enhance workflow:
- with limits: Enforce specific resource limits for commands, e.g.,
limits -m 1024 rsync -av /src /dest
- with systemd: Manage process resource limits in systemd unit files using the
Ulimit
directive.
Related Commands
- limits: View resource limits for a specific process.
- sysctl: Modify various kernel parameters, including resource limits.
- prlimit: Set and retrieve resource limits for a process programmatically.