11use procfs:: process:: Process ;
22
3- pub ( super ) struct ProcessDescendentsIterator {
3+ // Iterator which, given a process ID, returns the process and all its descendants
4+ pub ( super ) struct ProcessDescendantsIterator {
45 stack : Vec < Process > ,
56}
67
7- impl ProcessDescendentsIterator {
8+ impl ProcessDescendantsIterator {
89 pub ( super ) fn new ( parent_pid : i32 ) -> Self {
910 Self {
1011 stack : vec ! [
@@ -15,7 +16,7 @@ impl ProcessDescendentsIterator {
1516 }
1617}
1718
18- impl Iterator for ProcessDescendentsIterator {
19+ impl Iterator for ProcessDescendantsIterator {
1920 type Item = Process ;
2021
2122 fn next ( & mut self ) -> Option < Self :: Item > {
@@ -44,6 +45,9 @@ mod tests {
4445 use std:: io:: BufReader ;
4546 use std:: process:: { Command , Stdio } ;
4647
48+ /// Test the ProcessDescendentsIterator by creating a process tree.
49+ /// Each process will print its PID to stdout.
50+ /// The test will read the PIDs from stdout and check that the iterator returns all of them.
4751 #[ test]
4852 fn process_descendants_iterator ( ) {
4953 const NB_PROCESSES_PER_LEVEL : usize = 3 ;
@@ -71,7 +75,7 @@ mod tests {
7175 assert ! ( children_pids. insert( pid) ) ;
7276 }
7377
74- for process in ProcessDescendentsIterator :: new ( child. id ( ) as i32 ) {
78+ for process in ProcessDescendantsIterator :: new ( child. id ( ) as i32 ) {
7579 assert ! (
7680 children_pids. remove( & process. pid( ) ) ,
7781 "ProcessDescendentsIterator returned unexpected PID {pid}" ,
0 commit comments