|
|
@@ -21,6 +21,14 @@ impl Process {
|
|
21
|
21
|
}
|
|
22
|
22
|
}
|
|
23
|
23
|
|
|
|
24
|
+ fn me() -> Self {
|
|
|
25
|
+ if let Ok(my_pid) = pid::stat_self() {
|
|
|
26
|
+ Process::new(my_pid.pid)
|
|
|
27
|
+ } else {
|
|
|
28
|
+ panic!("Internal Error: I don't have a PID but I am running.")
|
|
|
29
|
+ }
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
24
|
32
|
/// Prüft ob das Prozess-Struct ein Elternprozess besitzt.
|
|
25
|
33
|
pub fn has_parent(&self) -> bool {
|
|
26
|
34
|
self.ppid != 0
|
|
|
@@ -59,9 +67,9 @@ impl Process {
|
|
59
|
67
|
}
|
|
60
|
68
|
}
|
|
61
|
69
|
|
|
62
|
|
-/// Erstellt einen 'Process' aus der übergebenen PID und
|
|
63
|
|
-/// Gibt über Rekursion über die Eltern eine Prozesskette aus.
|
|
64
|
|
-/// Fängt mögliche Fehler ab und
|
|
|
70
|
+/// Erstellt einen 'Process' aus der übergebenen PID und gibt die Prozesskette
|
|
|
71
|
+/// und fängt mögliche Fehler ab.
|
|
|
72
|
+///
|
|
65
|
73
|
pub fn print(pid:pid_t) -> bool {
|
|
66
|
74
|
|
|
67
|
75
|
if let Err(_) = pid::stat(pid) {
|
|
|
@@ -69,18 +77,17 @@ pub fn print(pid:pid_t) -> bool {
|
|
69
|
77
|
return false
|
|
70
|
78
|
}
|
|
71
|
79
|
|
|
72
|
|
- if let Ok(my_pid) = pid::stat_self() {
|
|
73
|
|
- let my_proc = Process::new(my_pid.pid);
|
|
74
|
80
|
|
|
75
|
|
- if !my_proc.has_parent_with_pid(pid) {
|
|
76
|
|
- println!("This Process has no parent {}", pid);
|
|
77
|
|
- return false
|
|
78
|
|
- }
|
|
|
81
|
+ let my_proc = Process::me();
|
|
79
|
82
|
|
|
80
|
|
- let mut output = String::new();
|
|
81
|
|
- my_proc.print_recursive(pid, &mut output);
|
|
82
|
|
- println!("{}", output);
|
|
|
83
|
+ if !my_proc.has_parent_with_pid(pid) {
|
|
|
84
|
+ println!("This Process has no parent {}", pid);
|
|
|
85
|
+ return false
|
|
83
|
86
|
}
|
|
84
|
87
|
|
|
|
88
|
+ let mut output = String::new();
|
|
|
89
|
+ my_proc.print_recursive(pid, &mut output);
|
|
|
90
|
+ println!("{}", output);
|
|
|
91
|
+
|
|
85
|
92
|
true
|
|
86
|
93
|
}
|