rlimit
Resource limits
Examples
Set resource limit
use ;
const DEFAULT_SOFT_LIMIT: u64 = 4 * 1024 * 1024;
const DEFAULT_HARD_LIMIT: u64 = 8 * 1024 * 1024;
assert!;
let soft = 16384;
let hard = soft * 2;
assert!;
Get resource limit
use ;
assert!;
assert_eq!;
Increase NOFILE limit
See the example nofile.
You can also use the tools in rlimit::utils.
use increase_nofile_limit;
increase_nofile_limit.unwrap;
increase_nofile_limit.unwrap;
Troubleshoot
Failed to increase NOFILE to hard limit on macOS
On macOS, getrlimit by default reports that the hard limit is
unlimited, but there is usually a stricter hard limit discoverable
via sysctl (kern.maxfilesperproc). Failing to discover this secret stricter hard limit will
cause the call to setrlimit to fail.
rlimit::utils::increase_nofile_limit respects kern.maxfilesperproc.