rlimit

![Latest Version] ![Documentation] ![License]

Resource limits

Examples

Set resource limit

```rust use rlimit::{setrlimit, Resource};

const DEFAULTSOFTLIMIT: u64 = 4 * 1024 * 1024; const DEFAULTHARDLIMIT: u64 = 8 * 1024 * 1024; assert!(Resource::FSIZE.set(DEFAULTSOFTLIMIT, DEFAULTHARDLIMIT).is_ok());

let soft = 16384; let hard = soft * 2; assert!(setrlimit(Resource::NOFILE, soft, hard).is_ok()); ```

Get resource limit

```rust use rlimit::{getrlimit, Resource};

assert!(Resource::NOFILE.get().isok()); asserteq!(getrlimit(Resource::CPU).unwrap(), (rlimit::INFINITY, rlimit::INFINITY)); ```

Increase NOFILE limit

See the example nofile.

You can also use the tools in rlimit::utils.

rust 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.