-
Notifications
You must be signed in to change notification settings - Fork 103
/
shm.rs
28 lines (24 loc) · 977 Bytes
/
shm.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
extern crate procfs;
/// List processes using posix shared memory segments
fn main() {
let shared_memory_vec = procfs::Shm::new().unwrap();
for shared_memory in &shared_memory_vec {
println!("key: {}, shmid: {}", shared_memory.key, shared_memory.shmid);
println!("============");
for prc in procfs::process::all_processes().unwrap() {
match prc.smaps() {
Ok(memory_maps) => {
for (memory_map, _memory_map_data) in &memory_maps {
if let procfs::process::MMapPath::Vsys(key) = memory_map.pathname {
if key == shared_memory.key && memory_map.inode == shared_memory.shmid {
println!("{}: {:?}", prc.pid, prc.cmdline().unwrap());
}
}
}
}
Err(_) => continue,
}
}
println!();
}
}