[−][src]Crate sysctl
A simplified interface to the sysctl
system call.
Example: Get value
#[cfg(any(target_os = "macos", target_os = "freebsd"))] const CTLNAME: &str = "kern.ostype"; #[cfg(any(target_os = "linux", target_os = "android"))] const CTLNAME: &str = "kernel.ostype"; let ctl = sysctl::Ctl::new(CTLNAME).unwrap(); let desc = ctl.description().unwrap(); println!("Description: {}", desc); let val = ctl.value().unwrap(); println!("Value: {}", val); // On Linux all sysctls are String type. Use the following for // cross-platform compatibility: let str_val = ctl.value_string().unwrap(); println!("String value: {}", val);
Example: Get value as struct
// Not available on Linux #[derive(Debug, Default)] #[repr(C)] struct ClockInfo { hz: libc::c_int, /* clock frequency */ tick: libc::c_int, /* micro-seconds per hz tick */ spare: libc::c_int, stathz: libc::c_int, /* statistics clock frequency */ profhz: libc::c_int, /* profiling clock frequency */ } let val: Box<ClockInfo> = sysctl::Ctl::new("kern.clockrate").unwrap().value_as().unwrap(); println!("{:?}", val);
Structs
Ctl | This struct represents a system control. |
CtlFlags | |
CtlInfo | A structure representing control metadata |
CtlIter | An iterator over Sysctl entries. |
Temperature | A custom type for temperature sysctls. |
Enums
CtlType | An Enum that represents a sysctl's type information. |
CtlValue | An Enum that holds all values returned by sysctl calls.
Extract inner value with |
SysctlError |
Constants
Traits
Sysctl |