Crates.io | sysctl |
lib.rs | sysctl |
version | 0.6.0 |
source | src |
created_at | 2017-05-09 15:01:56.373198 |
updated_at | 2024-09-10 20:23:05.435933 |
description | Simplified interface to libc::sysctl |
homepage | |
repository | https://github.com/johalun/sysctl-rs |
max_upload_size | |
id | 13887 |
size | 96,914 |
This crate provides a safe interface for reading and writing information to the kernel using the sysctl interface.
FreeBSD, Linux, macOS, iOS, tvOS, and visionOS are supported. Contributions for improvements and other platforms are welcome.
Documentation is available on docs.rs
Add to Cargo.toml
[dependencies]
sysctl = "*"
Ctl
take a mutable reference to self
on macOS/iOS.sysctl comes with several examples, see the examples folder:
value.rs
: shows how to get a sysctl valuevalue_as.rs
: parsing values as structuresvalue_string.rs
: parsing values as string. Use this for cross platform compatibility since all sysctls are strings on Linux.value_oid_as.rs
: getting a sysctl from OID constants from the libc
crate.set_value.rs
: shows how to set a sysctl valuestruct.rs
: reading data into a structtemperature.rs
: parsing temperaturesiterate.rs
: showcases iteration over the sysctl treeRun with:
$ cargo run --example iterate
Or to use in your program:
extern crate sysctl;
use sysctl::Sysctl;
fn main() {
let ctl = sysctl::Ctl::new("kern.osrevision").unwrap();
println!("Description: {}", ctl.description().unwrap());
println!("Value: {}", ctl.value_string().unwrap());
}