|
|
@@ -1,31 +1,53 @@
|
|
1
|
|
-use procinfo::pid::Stat;
|
|
2
|
1
|
use procinfo::pid;
|
|
|
2
|
+use procinfo::loadavg;
|
|
3
|
3
|
|
|
4
|
4
|
pub fn self_pids() -> Result<(i32, i32), &'static str>{
|
|
5
|
5
|
match pid::stat_self() {
|
|
6
|
6
|
Ok(stat) => { Ok((stat.pid, stat.ppid)) }
|
|
7
|
|
- Err(_) => { Err("Fehler") }
|
|
|
7
|
+ Err(_) => { Err("PID not alive: PID and PPID not found") }
|
|
8
|
8
|
}
|
|
9
|
9
|
}
|
|
10
|
10
|
|
|
11
|
11
|
pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
|
|
12
|
12
|
match pid::stat(pid) {
|
|
13
|
13
|
Ok(stat) => { Ok(stat.command) }
|
|
14
|
|
- Err(_) => { Err("Fehler") }
|
|
|
14
|
+ Err(_) => { Err("PID not alive: no command name found") }
|
|
15
|
15
|
}
|
|
16
|
16
|
}
|
|
17
|
17
|
|
|
18
|
|
-pub fn get_last_created_command() -> Result<String, &'static str> {
|
|
19
|
|
- match pid::stat_self() {
|
|
20
|
|
- Ok(stat) => { Ok(stat.command) }
|
|
21
|
|
- Err(_) => { Err("Fehler") }
|
|
|
18
|
+/*pub fn get_last_created_command() -> Result<String, &'static str> {
|
|
|
19
|
+ match loadavg() {
|
|
|
20
|
+ Ok(stat) => {
|
|
|
21
|
+ let last_pid = stat.last_created_pid;
|
|
|
22
|
+ match pid::stat(last_pid) {
|
|
|
23
|
+ Ok(st) => { Ok(st.command) }
|
|
|
24
|
+ Err(_) => { Err("No last command via PID found") }
|
|
|
25
|
+ }
|
|
|
26
|
+ }
|
|
|
27
|
+ Err(_) => { Err("No last command via PID found") }
|
|
22
|
28
|
}
|
|
23
|
|
-
|
|
24
|
|
-}
|
|
|
29
|
+}*/
|
|
25
|
30
|
|
|
26
|
31
|
pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
|
|
27
|
32
|
match pid::stat(pid) {
|
|
28
|
33
|
Ok(stat) => { Ok(stat.num_threads as u32) }
|
|
29
|
|
- Err(_) => { Err("Fehler") }
|
|
|
34
|
+ Err(_) => { Err("PID not alive: no threads counted") }
|
|
|
35
|
+ }
|
|
|
36
|
+}
|
|
|
37
|
+
|
|
|
38
|
+pub fn get_task_total() -> Result<u32, &'static str> {
|
|
|
39
|
+ match loadavg() {
|
|
|
40
|
+ Ok(stat) => { Ok(stat.tasks_total) }
|
|
|
41
|
+ Err(_) => { Err("No total count of tasks in system found") }
|
|
|
42
|
+ }
|
|
|
43
|
+}
|
|
|
44
|
+
|
|
|
45
|
+pub fn get_ownprocess_mem() -> Result<(usize, usize, usize), &'static str> {
|
|
|
46
|
+ match pid::stat_self() {
|
|
|
47
|
+ Ok(stat) => {
|
|
|
48
|
+ let csize = stat.end_code - stat.start_code;
|
|
|
49
|
+ let dsize = stat.end_data - stat.start_data;
|
|
|
50
|
+ Ok((stat.vsize, csize, dsize)) }
|
|
|
51
|
+ Err(_) => { Err("PID not alive: no memory found") }
|
|
30
|
52
|
}
|
|
31
|
53
|
}
|