18 releases

Uses old Rust 2015

0.6.0 Sep 10, 2024
0.5.5 Oct 31, 2023
0.5.4 Dec 9, 2022
0.5.2 Aug 16, 2022
0.1.2 May 23, 2017

#7 in Unix APIs

Download history 36421/week @ 2024-08-01 41749/week @ 2024-08-08 37206/week @ 2024-08-15 47807/week @ 2024-08-22 41341/week @ 2024-08-29 43923/week @ 2024-09-05 33578/week @ 2024-09-12 37404/week @ 2024-09-19 46888/week @ 2024-09-26 38013/week @ 2024-10-03 47626/week @ 2024-10-10 45298/week @ 2024-10-17 45296/week @ 2024-10-24 45800/week @ 2024-10-31 41418/week @ 2024-11-07 67436/week @ 2024-11-14

210,278 downloads per month
Used in 187 crates (48 directly)

MIT license

90KB
2K SLoC

This crate provides a safe interface for reading and writing information to the kernel using the sysctl interface.

Build Status

Current Version

FreeBSD, Linux, macOS, iOS, tvOS, and visionOS are supported. Contributions for improvements and other platforms are welcome.

Documentation

Documentation is available on docs.rs

Usage

Add to Cargo.toml

[dependencies]
sysctl = "*"

macOS/iOS

  • Due to limitations in the sysctl(3) API, many of the methods of the Ctl take a mutable reference to self on macOS/iOS.
  • Sysctl descriptions are not available on macOS/iOS and Linux.
  • Some tests failures are ignored, as the respective sysctls do not exist on macos.

Example

sysctl comes with several examples, see the examples folder:

  • value.rs: shows how to get a sysctl value
  • value_as.rs: parsing values as structures
  • value_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 value
  • struct.rs: reading data into a struct
  • temperature.rs: parsing temperatures
  • iterate.rs: showcases iteration over the sysctl tree

Run 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());
}

Dependencies

~0.4–7.5MB
~60K SLoC