Skip to content
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

NameTypeDirDescription
whichu_int-
rlpstruct rlimit-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard195
xnu-1486.2.11195
xnu-1504.15.3195
xnu-1504.3.12195
xnu-1504.7.4195
xnu-1504.9.17195
xnu-1504.9.26195
xnu-1504.9.37195

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