Expand description
rlimit - Resource limits.
§Examples
§Set resource limit
use rlimit::{setrlimit, Resource};
const DEFAULT_SOFT_LIMIT: u64 = 4 * 1024 * 1024;
const DEFAULT_HARD_LIMIT: u64 = 8 * 1024 * 1024;
assert!(Resource::FSIZE.set(DEFAULT_SOFT_LIMIT, DEFAULT_HARD_LIMIT).is_ok());
let soft = 16384;
let hard = soft * 2;
assert!(setrlimit(Resource::NOFILE, soft, hard).is_ok());§Get resource limit
use rlimit::{getrlimit, Resource};
assert!(Resource::NOFILE.get().is_ok());
assert_eq!(getrlimit(Resource::CPU).unwrap(), (rlimit::INFINITY, rlimit::INFINITY));§Increase NOFILE limit
See the example nofile.
You can also use the tools in rlimit::utils.
use rlimit::utils::increase_nofile_limit;
increase_nofile_limit(10240).unwrap();
increase_nofile_limit(u64::MAX).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.
Modules§
- utils
- Some tools for operating resource limits.
Structs§
- Proc
Limit - [Linux] A process’s resource limit field.
- Proc
Limits - [Linux] A process’s resource limits. It is parsed from the proc filesystem.
- Resource
- A kind of resource.
Constants§
- INFINITY
- A value indicating no limit.
- SAVED_
CUR - A value indicating an unrepresentable saved soft limit.
- SAVED_
MAX - A value indicating an unrepresentable saved hard limit.
Functions§
- getrlimit
- Get resource limits.
- prlimit
- [Linux] Set and get the resource limits of an arbitrary process.
- setrlimit
- Set resource limits.
Type Aliases§
- RawResource
- Integer type used for resource values.