Linux Command Reference ยท Processes and Signals
Bash ulimit command
Reference for the Bash ulimit builtin: show and set limits on open files, processes, memory, file size and CPU time, soft versus hard limits, and permanent settings.
ulimit shows or sets limits on the resources the current shell and every program it starts may use: how many files can be open, how many processes you may have, how big a file or core dump can grow, how much CPU time a process may burn. Limits protect a machine from runaway programs, and ulimit -n is the usual fix for "Too many open files".
Every limit has two values. The soft limit is the one the kernel enforces. The hard limit is the ceiling to which the soft limit may be raised. Any user can lower either; only root can raise a hard limit. Child processes inherit both, so changing a limit affects the shell and what it launches, never the parent.
ulimit [-SH] [-RESOURCE] [LIMIT]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
ulimit [-SH] -a ulimit [-SH] -n [LIMIT]
LIMIT is a number, or unlimited, hard or soft. Without LIMIT the current value is printed. Without -S or -H, setting changes both; reading shows the soft limit.
| Option | Resource (unit) |
|---|---|
-n |
Open file descriptors. |
-u |
Processes for the user. |
-f |
Largest file the shell and children may write (1024-byte blocks). |
-c |
Size of core files (512-byte blocks in POSIX mode; Bash uses 1024). |
-t |
CPU time in seconds. |
-v |
Virtual memory (KB). |
-m |
Resident memory (KB; mostly ignored by modern Linux). |
-s |
Stack size (KB). |
-l |
Locked memory (KB). |
-a |
Print all limits. |
-S, -H |
Operate on the soft or the hard limit. |
Returns: 0 on success; non-zero when the new value is not allowed (ulimit: open files: cannot modify limit: Operation not permitted).
Usage notes
- A limit is per process tree.
ulimitin a script does not change your login shell; put it in a subshell( ... )when you want it for one command. - Persistent values. Edit
/etc/security/limits.confor/etc/security/limits.d/*.conf(applied by PAM at login), orLimitNOFILE=in a systemd unit. A shellulimitis lost on exit. - Too many open files. Servers often need 10,000 or more. Raise the soft limit up to the hard limit with
ulimit -n 65536. - Fork bombs.
ulimit -ucaps the processes per user, one reason why shared systems set it. - Core dumps.
ulimit -c unlimitedallows full core files so you can debug a crash; most distributions default to 0. -vand-m. Memory limits are crude. Containers and cgroups (systemdMemoryMax=) are the modern way to cap memory.- Limits do not stack up. Each process gets the same limit; ten processes can together use ten times a per-process limit.
Related
timeout,niceandrenice,kill,lsof- Lessons: Processes