[][src]Crate procshot_server

This crate can be used to continuously scan over /proc filesystem and store it in the struct EncoDecode. This struct is serialized and is written to the datadir`. This is a wrapper over the procfs crate, so the compatibility of this crate depends on the compatibility of the procfs crate.

The stored data is of type EncoDecode and can be read as:


use std::fs::File;
use std::io::Read;
use procshot_server::EncoDecode;
pub fn read_test_data() {
        let mut file = File::open("./test_data.procshot").unwrap();
        let mut data = Vec::new();
        file.read_to_end(&mut data).unwrap();
        let decoded: EncoDecode = bincode::deserialize(&data[..]).unwrap_or_else(|x| panic!("Error reading saved data. This was either created with an older version of procshot, or the file is corrupt. Error is {}", x));
        println!("Decoded test file data: {:#?}", decoded);



Config struct holds the user input when running the server. It is a bad design to hold the client's option as well in the same struct, but as of now, it is here.


EncodDecode is the struct that we use to hold additional metadata and write to disk as serialized data of the form let enc encoded: Vec<u8> = bincode::serialize(&encodecode).unwrap();.


PidStatus is the struct that holds the data that we store for each process' status. In this crate, we create a Vec<HashMap<i32, PidStatus>> which is a mapping of pid to its status.



Checks if the program is run as sudo (root) user. This doesn't check if the user has the privilege to read over all of /proc or write to the datadir but just checks if the uid passed to this is 0, and returns a Result


scan_proc continuously scans /proc and records all the processes. scan_proc omits the pids if status.vmpeak == None || prc.stat.rss == 0 || status.pid < 0. One file is created for each iteration and sleeps for delay seconds after each iteration. The example in the description can be used as a reference to read the stored struct.