Browse Source

Fixed pstree completly.

themultiplexer 8 years ago
parent
commit
b955d6fb2f
1 changed files with 9 additions and 7 deletions
  1. 9
    7
      hw4/task1/src/pstree.rs

+ 9
- 7
hw4/task1/src/pstree.rs View File

1
 use procinfo::pid;
1
 use procinfo::pid;
2
-use std::os::unix::raw::pid_t;
2
+use std::libc::
3
 
3
 
4
 struct Process {
4
 struct Process {
5
     name : String,
5
     name : String,
35
         if p.has_parent() {
35
         if p.has_parent() {
36
             return p.parent().has_parent_with_pid(pid)
36
             return p.parent().has_parent_with_pid(pid)
37
         }
37
         }
38
+
38
         false
39
         false
39
     }
40
     }
40
 
41
 
41
-    fn print_recursive(d, to_pid:pid_t, output: &mut String) {
42
+    fn print_recursive(&self, to_pid:pid_t, output: &mut String) {
42
 
43
 
43
         if output.len() == 0 {
44
         if output.len() == 0 {
44
-            *output = format!("{}({}){}", from.name, from.pid, output);
45
+            *output = format!("{}({}){}", self.name, self.pid, output);
45
         } else {
46
         } else {
46
-            *output = format!("{}({})---{}", from.name, from.pid, output);
47
+            *output = format!("{}({})---{}", self.name, self.pid, output);
47
         }
48
         }
48
 
49
 
49
-        if from.has_parent() && from.pid != to_pid {
50
-            Process::print_recursive(&from.parent(), to_pid, output);
50
+        if self.has_parent() && self.pid != to_pid {
51
+            self.parent().print_recursive(to_pid, output);
51
         }
52
         }
52
     }
53
     }
53
 }
54
 }
54
 
55
 
55
 pub fn print(pid:pid_t) -> bool {
56
 pub fn print(pid:pid_t) -> bool {
57
+
56
     if let Err(_) = pid::stat(pid) {
58
     if let Err(_) = pid::stat(pid) {
57
         println!("Invalid PID");
59
         println!("Invalid PID");
58
         return false
60
         return false
67
             return false
69
             return false
68
         }
70
         }
69
 
71
 
70
-        Process::print_recursive(&my_proc,pid, &mut output);
72
+        my_proc.print_recursive(pid, &mut output);
71
         println!("{}", output);
73
         println!("{}", output);
72
     }
74
     }
73
 
75
 

Loading…
Cancel
Save