Recognize the difference between hard and soft limits and modify existing resource limits

Author: name contact BSD flavour

Reviewer: name contact BSD flavour

Reviewer: name contact BSD flavour


Understand that resource limits are inherited by the shell as well as how to view their limits and change them both temporarily and permanently. In addition, understand the difference between soft and hard limits.


TODO: briefly explain

The shell builtin commands limit (in csh(1) shell) and ulimit (for sh(1) and ksh(1) shells) are used to set hard or soft limits on number of file descriptors, memory used, processes, CPU usage, and other system resources.

limits: set or display process resource limits, either prints or sets kernel resource limits and may optionally set environment variables like env(1) and run a program with the selected resources. (TODO: don't use man page verbatim)

login.conf: login class capability database (/etc/login.conf, ~/.login_conf)

sysctl: get or set kernel state

All the BSDs use sysctl to set parameters at boot time. On OpenBSD, examples of these tunable parameters are: kern.maxvnodes, kern.maxproc, kern.maxfiles and kern.maxlocksperuid. By changing the integer value of such settings, they will be at the new level on next boot.

View limits:

less /etc/login.conf or ~/.login_conf to see per user limits)

With limit (shell builtin command): limit [-h] [resource [maximum-use]]

Resources include: cputime, filesize, datasize, stacksize, coredumpsize, memoryuse, heapsize, descriptors (or openfiles), concurrency (TODO ???), memorylocked, maxproc, sbsize

Maximum-use: default descriptor size is "k" or kilobytes (except cputime)

Change limits:

Temporarily: set them with the ulimit (shell builtin command)

Permanently: 1) set them in login.conf 2) set them with limits 3) set them with builtin limit 4) set them with sysctl

Understand the difference between hard and soft limits: Hard limits set a ceiling on the value of the soft limits. Only the super user may raise the hard limits, but a user may raise or lower the current limits with the legal range.


Practice Exercises

More information

limit(1), limits(1), login.conf(5); sysctl(8) on NetBSD