|
|
@@ -1,5 +1,5 @@
|
|
1
|
1
|
use procinfo::pid;
|
|
2
|
|
-use std::os::unix::raw::pid_t;
|
|
|
2
|
+use std::libc::
|
|
3
|
3
|
|
|
4
|
4
|
struct Process {
|
|
5
|
5
|
name : String,
|
|
|
@@ -35,24 +35,26 @@ impl Process {
|
|
35
|
35
|
if p.has_parent() {
|
|
36
|
36
|
return p.parent().has_parent_with_pid(pid)
|
|
37
|
37
|
}
|
|
|
38
|
+
|
|
38
|
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
|
44
|
if output.len() == 0 {
|
|
44
|
|
- *output = format!("{}({}){}", from.name, from.pid, output);
|
|
|
45
|
+ *output = format!("{}({}){}", self.name, self.pid, output);
|
|
45
|
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
|
56
|
pub fn print(pid:pid_t) -> bool {
|
|
|
57
|
+
|
|
56
|
58
|
if let Err(_) = pid::stat(pid) {
|
|
57
|
59
|
println!("Invalid PID");
|
|
58
|
60
|
return false
|
|
|
@@ -67,7 +69,7 @@ pub fn print(pid:pid_t) -> bool {
|
|
67
|
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
|
73
|
println!("{}", output);
|
|
72
|
74
|
}
|
|
73
|
75
|
|