|
|
@@ -1,6 +1,8 @@
|
|
1
|
1
|
use procinfo::pid;
|
|
2
|
2
|
use procinfo::loadavg;
|
|
3
|
3
|
|
|
|
4
|
+/// Returns the PID and PPID of the current process.
|
|
|
5
|
+/// Throws an error if the current process doesn't exist (should never occur).
|
|
4
|
6
|
pub fn self_pids() -> Result<(i32, i32), &'static str>{
|
|
5
|
7
|
match pid::stat_self() {
|
|
6
|
8
|
Ok(stat) => { Ok((stat.pid, stat.ppid)) }
|
|
|
@@ -8,6 +10,8 @@ pub fn self_pids() -> Result<(i32, i32), &'static str>{
|
|
8
|
10
|
}
|
|
9
|
11
|
}
|
|
10
|
12
|
|
|
|
13
|
+/// Returns the command (string) belonging to the given PID.
|
|
|
14
|
+/// Throws an error if the given PID doesn't exist.
|
|
11
|
15
|
pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
|
|
12
|
16
|
match pid::stat(pid) {
|
|
13
|
17
|
Ok(stat) => { Ok(stat.command) }
|
|
|
@@ -15,6 +19,8 @@ pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
|
|
15
|
19
|
}
|
|
16
|
20
|
}
|
|
17
|
21
|
|
|
|
22
|
+/// Returns the last created command (string) of the system.
|
|
|
23
|
+/// Throws an error if there is no last Command.
|
|
18
|
24
|
pub fn get_last_created_command() -> Result<String, &'static str> {
|
|
19
|
25
|
match loadavg() {
|
|
20
|
26
|
Ok(stat) => {
|
|
|
@@ -28,6 +34,8 @@ pub fn get_last_created_command() -> Result<String, &'static str> {
|
|
28
|
34
|
}
|
|
29
|
35
|
}
|
|
30
|
36
|
|
|
|
37
|
+/// Returns the number of threads belonging to the given PID.
|
|
|
38
|
+/// Throws an error if the given PID doesn't exist.
|
|
31
|
39
|
pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
|
|
32
|
40
|
match pid::stat(pid) {
|
|
33
|
41
|
Ok(stat) => { Ok(stat.num_threads as u32) }
|
|
|
@@ -35,6 +43,8 @@ pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
|
|
35
|
43
|
}
|
|
36
|
44
|
}
|
|
37
|
45
|
|
|
|
46
|
+/// Returns the number of total tasks running in the system.
|
|
|
47
|
+/// Throws an error if the total number of tasks doesn't exist.
|
|
38
|
48
|
pub fn get_task_total() -> Result<u32, &'static str> {
|
|
39
|
49
|
match loadavg() {
|
|
40
|
50
|
Ok(stat) => { Ok(stat.tasks_total) }
|
|
|
@@ -42,6 +52,8 @@ pub fn get_task_total() -> Result<u32, &'static str> {
|
|
42
|
52
|
}
|
|
43
|
53
|
}
|
|
44
|
54
|
|
|
|
55
|
+/// Returns the size of the virtual, code and data memory size of the current process.
|
|
|
56
|
+/// Throws an error if the current process doesn't exist (should never occur).
|
|
45
|
57
|
pub fn get_ownprocess_mem() -> Result<(usize, usize, usize), &'static str> {
|
|
46
|
58
|
match pid::stat_self() {
|
|
47
|
59
|
Ok(stat) => {
|