Function get_process_maps

Source
pub fn get_process_maps(pid: Pid) -> Result<Vec<MapRange>>
Expand description

Gets a Vec of MapRange structs for the passed in PID. (Note that while this function is for Linux, the macOS, Windows, and FreeBSD variants have the same interface)

Examples found in repository?
examples/print_maps.rs (line 18)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}