17 releases

✓ Uses Rust 2018 edition

0.5.4 Oct 7, 2019
0.5.3 Jun 10, 2019
0.5.2 May 8, 2019
0.4.7 Mar 1, 2019
0.3.0 Jul 29, 2018

#21 in Unix APIs

Download history 204/week @ 2019-06-24 224/week @ 2019-07-01 141/week @ 2019-07-08 69/week @ 2019-07-15 82/week @ 2019-07-22 91/week @ 2019-07-29 166/week @ 2019-08-05 141/week @ 2019-08-12 224/week @ 2019-08-19 433/week @ 2019-08-26 227/week @ 2019-09-02 158/week @ 2019-09-09 247/week @ 2019-09-16 172/week @ 2019-09-23 146/week @ 2019-09-30

762 downloads per month
Used in 2 crates

MIT/Apache

155KB
3K SLoC

procfs

Click here to view the documentation for this crate: Documentation

This crate is an interface to the proc pseudo-filesystem on linux, which is normally mounted as /proc. Long-term, this crate aims to be fairly feature complete, but at the moment not all files are exposed. See the docs for info on what's supported.

Examples

There are several examples in the docs and in the examples folder of the code repository.

Here's a small example that prints out all processes that are running on the same tty as the calling process. This is very similar to what "ps" does in its default mode:

extern crate procfs;

fn main() {
    let me = procfs::Process::myself().unwrap();
    let tps = procfs::ticks_per_second().unwrap();

    println!("{: >5} {: <8} {: >8} {}", "PID", "TTY", "TIME", "CMD");

    let tty = format!("pty/{}", me.stat.tty_nr().1);
    for prc in procfs::all_processes() {
        if prc.stat.tty_nr == me.stat.tty_nr {
            // total_time is in seconds
            let total_time =
                (prc.stat.utime + prc.stat.stime) as f32 / (tps as f32);
            println!(
                "{: >5} {: <8} {: >8} {}",
                prc.stat.pid, tty, total_time, prc.stat.comm
            );
        }
    }
}

License

Licensed under either of

at your option.

Contribution

Contriutions are welcome, especially in the areas of documentation and testing on older kernels.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~18K SLoC