Bläddra i källkod

Added comments for all functions.

Lorenz Bung 8 år sedan
förälder
incheckning
7ee8de9db1
1 ändrade filer med 12 tillägg och 0 borttagningar
  1. 12
    0
      hw4/task1/src/readproc.rs

+ 12
- 0
hw4/task1/src/readproc.rs Visa fil

1
 use procinfo::pid;
1
 use procinfo::pid;
2
 use procinfo::loadavg;
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
 pub fn self_pids() -> Result<(i32, i32), &'static str>{
6
 pub fn self_pids() -> Result<(i32, i32), &'static str>{
5
     match pid::stat_self() {
7
     match pid::stat_self() {
6
         Ok(stat) => { Ok((stat.pid, stat.ppid)) }
8
         Ok(stat) => { Ok((stat.pid, stat.ppid)) }
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
 pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
15
 pub fn get_pid_command(pid: i32) -> Result<String, &'static str> {
12
     match pid::stat(pid) {
16
     match pid::stat(pid) {
13
         Ok(stat) => { Ok(stat.command) }
17
         Ok(stat) => { Ok(stat.command) }
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
 pub fn get_last_created_command() -> Result<String, &'static str> {
24
 pub fn get_last_created_command() -> Result<String, &'static str> {
19
     match loadavg() {
25
     match loadavg() {
20
         Ok(stat) => {
26
         Ok(stat) => {
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
 pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
39
 pub fn get_thread_count(pid: i32) -> Result<u32, &'static str> {
32
     match pid::stat(pid) {
40
     match pid::stat(pid) {
33
         Ok(stat) => { Ok(stat.num_threads as u32) }
41
         Ok(stat) => { Ok(stat.num_threads as u32) }
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
 pub fn get_task_total() -> Result<u32, &'static str> {
48
 pub fn get_task_total() -> Result<u32, &'static str> {
39
     match loadavg() {
49
     match loadavg() {
40
         Ok(stat) => { Ok(stat.tasks_total) }
50
         Ok(stat) => { Ok(stat.tasks_total) }
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
 pub fn get_ownprocess_mem() -> Result<(usize, usize, usize), &'static str> {
57
 pub fn get_ownprocess_mem() -> Result<(usize, usize, usize), &'static str> {
46
     match pid::stat_self() {
58
     match pid::stat_self() {
47
         Ok(stat) => {
59
         Ok(stat) => {

Laddar…
Avbryt
Spara