Giter Club home page Giter Club logo

sysctl-rs's Introduction

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

sysctl-rs's People

Contributors

35359595 avatar asomers avatar fabianfreyer avatar johalun avatar jvimal-eg avatar luozijun avatar mordak avatar nicklarsennz avatar phyber avatar stephanvanschaik avatar vv9k avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.