|
|
@@ -4,7 +4,7 @@ use procinfo::pid;
|
|
4
|
4
|
use self::libc::pid_t;
|
|
5
|
5
|
|
|
6
|
6
|
/// Datenstruktur für einen Prozess.
|
|
7
|
|
-struct Process {
|
|
|
7
|
+pub struct Process {
|
|
8
|
8
|
name : String,
|
|
9
|
9
|
pid : pid_t,
|
|
10
|
10
|
ppid : pid_t,
|
|
|
@@ -13,7 +13,7 @@ struct Process {
|
|
13
|
13
|
impl Process {
|
|
14
|
14
|
|
|
15
|
15
|
/// Erstellt eine Prozess-Datenstruktur aus procinfo::Stat.
|
|
16
|
|
- fn new(with_pid:pid_t) -> Self {
|
|
|
16
|
+ pub fn new(with_pid:pid_t) -> Self {
|
|
17
|
17
|
if let Ok(stat) = pid::stat(with_pid) {
|
|
18
|
18
|
Process{name: stat.command, pid:stat.pid, ppid:stat.ppid}
|
|
19
|
19
|
} else {
|
|
|
@@ -22,17 +22,17 @@ impl Process {
|
|
22
|
22
|
}
|
|
23
|
23
|
|
|
24
|
24
|
/// Prüft ob das Prozess-Struct ein Elternprozess besitzt.
|
|
25
|
|
- fn has_parent(&self) -> bool {
|
|
|
25
|
+ pub fn has_parent(&self) -> bool {
|
|
26
|
26
|
self.ppid != 0
|
|
27
|
27
|
}
|
|
28
|
28
|
|
|
29
|
29
|
/// Gibt den Elternprozess zurück.
|
|
30
|
|
- fn parent(&self) -> Self {
|
|
|
30
|
+ pub fn parent(&self) -> Self {
|
|
31
|
31
|
Process::new(self.ppid)
|
|
32
|
32
|
}
|
|
33
|
33
|
|
|
34
|
34
|
/// Prüft ob das Prozess-Struct einen (entfernten) Elternprozess mit dem übergebenen pid hat.
|
|
35
|
|
- fn has_parent_with_pid(&self, pid: pid_t) -> bool {
|
|
|
35
|
+ pub fn has_parent_with_pid(&self, pid: pid_t) -> bool {
|
|
36
|
36
|
if self.pid == pid {
|
|
37
|
37
|
return true
|
|
38
|
38
|
}
|
|
|
@@ -45,7 +45,7 @@ impl Process {
|
|
45
|
45
|
}
|
|
46
|
46
|
|
|
47
|
47
|
/// Gibt über Rekursion über die Eltern eine Prozesskette aus.
|
|
48
|
|
- fn print_recursive(&self, to_pid:pid_t, output: &mut String) {
|
|
|
48
|
+ pub fn print_recursive(&self, to_pid:pid_t, output: &mut String) {
|
|
49
|
49
|
|
|
50
|
50
|
if output.len() == 0 {
|
|
51
|
51
|
*output = format!("{}({}){}", self.name, self.pid, output);
|