Skip to content

Commit

Permalink
find all running processes in Linux via rustix (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Mar 1, 2024
1 parent 740b181 commit c070bbf
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 9 deletions.
249 changes: 248 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ edition = "2021"

[dependencies]
netstat2 = "0.9.1"
rustix = {version = "0.38.31", features = ["procfs", "fs"]}
[target.'cfg(not(target_os = "windows"))'.dependencies]
libproc = "0.14.2"
[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.53.0", features = ["Win32_Foundation", "Win32_System_Diagnostics_ToolHelp"] }
windows = { version = "0.53.0", features = ["Win32_Foundation", "Win32_System_Diagnostics_ToolHelp"] }
procfs = "0.16.0"
22 changes: 21 additions & 1 deletion src/platform/linux.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
use std::path::Path;
use std::str::FromStr;
use rustix::fs::{OFlags, Mode};

const ROOT: &str = "/proc";

pub(crate) fn hi() {
println!("Hi from Linux");
// procfs::process::all_processes().unwrap();
let root = rustix::fs::openat(
rustix::fs::CWD,
Path::new(ROOT),
OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC,
Mode::empty()
).unwrap();
let dir = rustix::fs::Dir::read_from(root).unwrap();
for entry in dir {
if let Some(Ok(e)) = entry {
if let Ok(pid) = i32::from_str(&e.file_name().to_string_lossy()) {
Some(Process::new_with_root(self.root.join(pid.to_string())));
}
}
}
}
Loading

0 comments on commit c070bbf

Please sign in to comment.