Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.github/ | H | 03-May-2022 | - | 140 | 127 | |
examples/ | H | 03-May-2022 | - | 38 | 30 | |
scripts/ | H | 03-May-2022 | - | 433 | 359 | |
src/ | H | 03-May-2022 | - | 1,224 | 833 | |
tests/it/ | H | 03-May-2022 | - | 204 | 159 | |
.cargo-checksum.json | H A D | 03-May-2022 | 89 | 1 | 1 | |
.cargo_vcs_info.json | H A D | 01-Jan-1970 | 74 | 6 | 5 | |
.gitignore | H A D | 01-Jan-1970 | 60 | 9 | 6 | |
.travis.yml | H A D | 01-Jan-1970 | 240 | 25 | 18 | |
Cargo.lock | H A D | 01-Jan-1970 | 367 | 17 | 14 | |
Cargo.toml | H A D | 01-Jan-1970 | 901 | 28 | 26 | |
Cargo.toml.orig-cargo | H A D | 01-Jan-1970 | 370 | 18 | 15 | |
LICENSE | H A D | 01-Jan-1970 | 1 KiB | 22 | 17 | |
README.md | H A D | 01-Jan-1970 | 1.6 KiB | 59 | 42 | |
justfile | H A D | 01-Jan-1970 | 1 KiB | 31 | 21 |
README.md
1# rlimit 2 3[![Latest Version]][crates.io] 4[![Documentation]][docs.rs] 5![License] 6 7Resource limits 8 9[crates.io]: https://crates.io/crates/rlimit 10[Latest Version]: https://img.shields.io/crates/v/rlimit.svg 11[Documentation]: https://docs.rs/rlimit/badge.svg 12[docs.rs]: https://docs.rs/rlimit 13[License]: https://img.shields.io/crates/l/rlimit.svg 14 15## Examples 16### Set resource limit 17 18```rust 19use rlimit::{setrlimit, Resource}; 20 21const DEFAULT_SOFT_LIMIT: u64 = 4 * 1024 * 1024; 22const DEFAULT_HARD_LIMIT: u64 = 8 * 1024 * 1024; 23assert!(Resource::FSIZE.set(DEFAULT_SOFT_LIMIT, DEFAULT_HARD_LIMIT).is_ok()); 24 25let soft = 16384; 26let hard = soft * 2; 27assert!(setrlimit(Resource::NOFILE, soft, hard).is_ok()); 28``` 29### Get resource limit 30 31```rust 32use rlimit::{getrlimit, Resource}; 33 34assert!(Resource::NOFILE.get().is_ok()); 35assert_eq!(getrlimit(Resource::CPU).unwrap(), (rlimit::INFINITY, rlimit::INFINITY)); 36``` 37 38### Increase NOFILE limit 39 40See the example [nofile](https://github.com/Nugine/rlimit/tree/v0.6.2/examples/nofile.rs). 41 42You can also use the tools in `rlimit::utils`. 43 44```rust 45use rlimit::utils::increase_nofile_limit; 46increase_nofile_limit(10240).unwrap(); 47increase_nofile_limit(u64::MAX).unwrap(); 48``` 49 50## Troubleshoot 51### Failed to increase NOFILE to hard limit on macOS 52 53On macOS, getrlimit by default reports that the hard limit is 54unlimited, but there is usually a stricter hard limit discoverable 55via sysctl (`kern.maxfilesperproc`). Failing to discover this secret stricter hard limit will 56cause the call to setrlimit to fail. 57 58`rlimit::utils::increase_nofile_limit` respects `kern.maxfilesperproc`. 59