Skip to content

Commit

Permalink
Merge pull request prometheus#84 from wookietreiber/feature/pid_max
Browse files Browse the repository at this point in the history
adds pid_max
  • Loading branch information
eminence authored Jun 25, 2020
2 parents e6464ce + 1b0f4ab commit 7777515
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/sys/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ impl cmp::PartialOrd for Version {
}
}

/// Returns the maximum process ID number.
///
/// This is taken from `/proc/sys/kernel/pid_max`.
///
/// # Example
///
/// ```
/// let pid_max = procfs::sys::kernel::pid_max().unwrap();
///
/// let pid = 42; // e.g. from user input, CLI args, etc.
///
/// if pid > pid_max {
/// eprintln!("bad process ID: {}", pid)
/// } else {
/// println!("good process ID: {}", pid);
/// }
/// ```
pub fn pid_max() -> ProcResult<i32> {
read_value("/proc/sys/kernel/pid_max")
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -142,4 +163,9 @@ mod tests {
fn test_current() {
let _ = Version::current().unwrap();
}

#[test]
fn test_pid_max() {
assert!(pid_max().is_ok());
}
}
2 changes: 1 addition & 1 deletion support.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ This is an approximate list of all the files under the `/proc` mount, and an ind
* [ ] `/proc/sys/kernel/overflowuid`
* [ ] `/proc/sys/kernel/panic`
* [ ] `/proc/sys/kernel/panic_on_oops`
* [ ] `/proc/sys/kernel/pid_max`
* [x] `/proc/sys/kernel/pid_max`
* [ ] `/proc/sys/kernel/powersave-nap`
* [ ] `/proc/sys/kernel/printk`
* [ ] `/proc/sys/kernel/pty`
Expand Down

0 comments on commit 7777515

Please sign in to comment.