Skip to content

Commit

Permalink
helper: Add threads
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 30, 2023
1 parent c4c07be commit 7eba6fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#[macro_use]
pub mod macros;
pub mod threads;
24 changes: 24 additions & 0 deletions src/helper/threads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::thread;
use std::time::Duration;
use sysinfo::{ProcessExt, System, SystemExt};
use tracing::*;

pub fn start_thread_counter_thread() {
let mut system = System::new_all();
let pid = sysinfo::get_current_pid().expect("Failed to get current PID.");
thread::spawn(move || loop {
system.refresh_processes();
let child_processes: Vec<_> = system
.processes()
.iter()
.filter(|(_, process)| {
process
.parent()
.map_or(false, |parent_pid| parent_pid == pid)
})
.collect();

info!("Number of child processes: {}", child_processes.len(),);
thread::sleep(Duration::from_secs(1));
});
}

0 comments on commit 7eba6fd

Please sign in to comment.