|
|
@@ -3,13 +3,13 @@ use procinfo::pid;
|
|
3
|
3
|
/// Datenstruktur für einen Prozess.
|
|
4
|
4
|
pub struct Process {
|
|
5
|
5
|
name: String,
|
|
6
|
|
- pid: u32,
|
|
7
|
|
- ppid: u32,
|
|
|
6
|
+ pid: i32,
|
|
|
7
|
+ ppid: i32,
|
|
8
|
8
|
}
|
|
9
|
9
|
|
|
10
|
10
|
impl Process {
|
|
11
|
11
|
/// Erstellt eine Prozess-Datenstruktur aus procinfo::Stat.
|
|
12
|
|
- pub fn new(with_pid: u32) -> Self {
|
|
|
12
|
+ pub fn new(with_pid: i32) -> Self {
|
|
13
|
13
|
if let Ok(stat) = pid::stat(with_pid) {
|
|
14
|
14
|
Process {
|
|
15
|
15
|
name: stat.command,
|
|
|
@@ -41,7 +41,7 @@ impl Process {
|
|
41
|
41
|
}
|
|
42
|
42
|
|
|
43
|
43
|
/// Prüft ob das Prozess-Struct einen (entfernten) Elternprozess mit dem übergebenen pid hat.
|
|
44
|
|
- pub fn has_parent_with_pid(&self, pid: u32) -> bool {
|
|
|
44
|
+ pub fn has_parent_with_pid(&self, pid: i32) -> bool {
|
|
45
|
45
|
if self.pid == pid {
|
|
46
|
46
|
return true;
|
|
47
|
47
|
}
|
|
|
@@ -54,7 +54,7 @@ impl Process {
|
|
54
|
54
|
}
|
|
55
|
55
|
|
|
56
|
56
|
/// Gibt über Rekursion über die Eltern eine Prozesskette aus.
|
|
57
|
|
- pub fn print_recursive(&self, to_pid: u32, output: &mut String) {
|
|
|
57
|
+ pub fn print_recursive(&self, to_pid: i32, output: &mut String) {
|
|
58
|
58
|
|
|
59
|
59
|
if output.len() == 0 {
|
|
60
|
60
|
*output = format!("{}({}){}", self.name, self.pid, output);
|
|
|
@@ -70,7 +70,7 @@ impl Process {
|
|
70
|
70
|
|
|
71
|
71
|
/// Geht von eigenem Prozess aus und gibt die Prozesskette bis zum übergebenem PID aus
|
|
72
|
72
|
/// und fängt mögliche Fehler ab.
|
|
73
|
|
-pub fn print(pid: u32) -> bool {
|
|
|
73
|
+pub fn print(pid: i32) -> bool {
|
|
74
|
74
|
|
|
75
|
75
|
if let Err(_) = pid::stat(pid) {
|
|
76
|
76
|
println!("Invalid PID");
|