-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
find all running processes in Linux via rustix (WIP)
- Loading branch information
Showing
4 changed files
with
278 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.