1 | #[cfg (linux_kernel)] |
2 | use crate::process::Pid; |
3 | use crate::{backend, io}; |
4 | |
5 | pub use backend::process::types::Resource; |
6 | |
7 | /// `struct rlimit`—Current and maximum values used in [`getrlimit`], |
8 | /// [`setrlimit`], and [`prlimit`]. |
9 | #[derive (Debug, Clone, PartialEq, Eq)] |
10 | pub struct Rlimit { |
11 | /// Current effective, “soft”, limit. |
12 | pub current: Option<u64>, |
13 | /// Maximum, “hard”, value that `current` may be dynamically increased to. |
14 | pub maximum: Option<u64>, |
15 | } |
16 | |
17 | /// `getrlimit(resource)`—Get a process resource limit value. |
18 | /// |
19 | /// # References |
20 | /// - [POSIX] |
21 | /// - [Linux] |
22 | /// |
23 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html |
24 | /// [Linux]: https://man7.org/linux/man-pages/man2/getrlimit.2.html |
25 | #[inline ] |
26 | pub fn getrlimit(resource: Resource) -> Rlimit { |
27 | backend::process::syscalls::getrlimit(limit:resource) |
28 | } |
29 | |
30 | /// `setrlimit(resource, new)`—Set a process resource limit value. |
31 | /// |
32 | /// # References |
33 | /// - [POSIX] |
34 | /// - [Linux] |
35 | /// |
36 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setrlimit.html |
37 | /// [Linux]: https://man7.org/linux/man-pages/man2/setrlimit.2.html |
38 | #[inline ] |
39 | pub fn setrlimit(resource: Resource, new: Rlimit) -> io::Result<()> { |
40 | backend::process::syscalls::setrlimit(limit:resource, new) |
41 | } |
42 | |
43 | /// `prlimit(pid, resource, new)`—Get and set a process resource limit value. |
44 | /// |
45 | /// # References |
46 | /// - [Linux] |
47 | /// |
48 | /// [Linux]: https://man7.org/linux/man-pages/man2/prlimit.2.html |
49 | #[cfg (linux_kernel)] |
50 | #[inline ] |
51 | pub fn prlimit(pid: Option<Pid>, resource: Resource, new: Rlimit) -> io::Result<Rlimit> { |
52 | backend::process::syscalls::prlimit(pid, limit:resource, new) |
53 | } |
54 | |