sysctl 0.4.6

Simplified interface to libc::sysctl

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 is available on


Add to Cargo.toml

sysctl = "0.4.4"


  • 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.


sysctl comes with several examples, see the examples folder:

  • shows how to get a sysctl value
  • parsing values as structures
  • parsing values as string. Use this for cross platform compatibility since all sysctls are strings on Linux.
  • getting a sysctl from OID constants from the libc crate.
  • shows how to set a sysctl value
  • reading data into a struct
  • parsing temperatures
  • 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());