BSD syscall#195
svc · unix #195
setrlimit
Sets the soft and hard limits for a resource.
Prototype
int setrlimit(u_int which, struct rlimit *rlp);Returns: int
Arguments
| Name | Type | Dir | Description |
|---|---|---|---|
| which | u_int | - | |
| rlp | struct rlimit | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 195 |
| xnu-1486.2.11 | — | 195 |
| xnu-1504.15.3 | — | 195 |
| xnu-1504.3.12 | — | 195 |
| xnu-1504.7.4 | — | 195 |
| xnu-1504.9.17 | — | 195 |
| xnu-1504.9.26 | — | 195 |
| xnu-1504.9.37 | — | 195 |
Examples
Raise fd limit
#include <sys/resource.h>
struct rlimit rl;
getrlimit(RLIMIT_NOFILE, &rl);
rl.rlim_cur = rl.rlim_max;
setrlimit(RLIMIT_NOFILE, &rl);Notes
Unprivileged callers can lower the hard limit or raise the soft limit up to it; only root can raise hard limits. Some macOS limits (RLIMIT_NOFILE, RLIMIT_NPROC) are additionally clamped by sysctl values like kern.maxfilesperproc and kern.maxprocperuid. Raising RLIMIT_STACK does not retroactively grow existing thread stacks.
Related APIs
getrlimitproc_rlimit_controlgetrusagegetdtablesizesetpriority