themultiplexer 8 роки тому
джерело
коміт
52ecb7c209
2 змінених файлів з 8 додано та 7 видалено
  1. 1
    0
      hw4/task1/Cargo.toml
  2. 7
    7
      hw4/task1/src/pstree.rs

+ 1
- 0
hw4/task1/Cargo.toml Переглянути файл

@@ -5,3 +5,4 @@ authors = ["Joshua Rutschmann <joshua.rutschmann@gmx.de>"]
5 5
 
6 6
 [dependencies]
7 7
 procinfo = "^0.4.2"
8
+libc = "0.2"

+ 7
- 7
hw4/task1/src/pstree.rs Переглянути файл

@@ -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

Завантаження…
Відмінити
Зберегти