-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patrick José Pereira <[email protected]>
- Loading branch information
1 parent
c4c07be
commit 7eba6fd
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
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,2 +1,3 @@ | ||
#[macro_use] | ||
pub mod macros; | ||
pub mod threads; |
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 |
---|---|---|
@@ -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)); | ||
}); | ||
} |