17 releases

Uses old Rust 2015

0.5.5 Oct 31, 2023
0.5.4 Dec 9, 2022
0.5.2 Aug 16, 2022
0.4.4 Mar 1, 2022
0.1.2 May 23, 2017

#13 in Unix APIs

Download history 31883/week @ 2023-12-06 33396/week @ 2023-12-13 26832/week @ 2023-12-20 14006/week @ 2023-12-27 29581/week @ 2024-01-03 27084/week @ 2024-01-10 32723/week @ 2024-01-17 32825/week @ 2024-01-24 30019/week @ 2024-01-31 33242/week @ 2024-02-07 28318/week @ 2024-02-14 27691/week @ 2024-02-21 35530/week @ 2024-02-28 32656/week @ 2024-03-06 36034/week @ 2024-03-13 28428/week @ 2024-03-20

138,370 downloads per month
Used in 149 crates (39 directly)

MIT license

88KB
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 and iOS 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.5–1.3MB
~26K SLoC