10 releases (5 breaking)

0.6.2 Jul 15, 2021
0.5.4 Mar 1, 2021
0.5.3 Nov 9, 2020
0.3.0 Jul 29, 2019

#9 in Unix APIs

Download history 4276/week @ 2021-04-05 3991/week @ 2021-04-12 4140/week @ 2021-04-19 3486/week @ 2021-04-26 3820/week @ 2021-05-03 4579/week @ 2021-05-10 4596/week @ 2021-05-17 4366/week @ 2021-05-24 9163/week @ 2021-05-31 10891/week @ 2021-06-07 10662/week @ 2021-06-14 7722/week @ 2021-06-21 6056/week @ 2021-06-28 7639/week @ 2021-07-05 7551/week @ 2021-07-12 5425/week @ 2021-07-19

27,380 downloads per month
Used in less than 11 crates

MIT license

55KB
1K SLoC

Rust 833 SLoC // 0.0% comments Python 241 SLoC // 0.3% comments

rlimit

Latest Version Documentation License

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.

Dependencies