• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H03-May-2022-140127

examples/H03-May-2022-3830

scripts/H03-May-2022-433359

src/H03-May-2022-1,224833

tests/it/H03-May-2022-204159

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D01-Jan-197060 96

.travis.ymlH A D01-Jan-1970240 2518

Cargo.lockH A D01-Jan-1970367 1714

Cargo.tomlH A D01-Jan-1970901 2826

Cargo.toml.orig-cargoH A D01-Jan-1970370 1815

LICENSEH A D01-Jan-19701 KiB2217

README.mdH A D01-Jan-19701.6 KiB5942

justfileH A D01-Jan-19701 KiB3121

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