|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+extern crate libc;
|
|
|
2
|
+
|
|
1
|
3
|
use procinfo::pid;
|
|
2
|
|
-use std::libc::
|
|
|
4
|
+use self::libc::pid_t;
|
|
3
|
5
|
|
|
4
|
6
|
struct Process {
|
|
5
|
7
|
name : String,
|
|
|
@@ -13,7 +15,7 @@ impl Process {
|
|
13
|
15
|
if let Ok(stat) = pid::stat(with_pid) {
|
|
14
|
16
|
Process{name: stat.command, pid:stat.pid, ppid:stat.ppid}
|
|
15
|
17
|
} else {
|
|
16
|
|
- Process{name: "".to_string(), pid:0, ppid:0}
|
|
|
18
|
+ panic!("Internal Error: Process not found")
|
|
17
|
19
|
}
|
|
18
|
20
|
}
|
|
19
|
21
|
|
|
|
@@ -26,14 +28,12 @@ impl Process {
|
|
26
|
28
|
}
|
|
27
|
29
|
|
|
28
|
30
|
fn has_parent_with_pid(&self, pid: pid_t) -> bool {
|
|
29
|
|
- let mut p = self;
|
|
30
|
|
-
|
|
31
|
|
- if p.pid == pid {
|
|
|
31
|
+ if self.pid == pid {
|
|
32
|
32
|
return true
|
|
33
|
33
|
}
|
|
34
|
34
|
|
|
35
|
|
- if p.has_parent() {
|
|
36
|
|
- return p.parent().has_parent_with_pid(pid)
|
|
|
35
|
+ if self.has_parent() {
|
|
|
36
|
+ return self.parent().has_parent_with_pid(pid)
|
|
37
|
37
|
}
|
|
38
|
38
|
|
|
39
|
39
|
false
|