Browse Source

Commented pstree.rs.

themultiplexer 8 years ago
parent
commit
f97360b8ef
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      hw5/task1/src/child/mod.rs

+ 7
- 2
hw5/task1/src/child/mod.rs View File

5
 
5
 
6
 mod pstree;
6
 mod pstree;
7
 
7
 
8
+/// Required function.
9
+/// Accepts parameter *start_pid* which will be root-process in the printed pstree.
10
+/// Parses parameter *arg* as the number of forked processes.
8
 pub fn run_childs(start_pid: i32, arg: &str) -> Result<(), String> {
11
 pub fn run_childs(start_pid: i32, arg: &str) -> Result<(), String> {
9
     let count = arg.parse::<u8>();
12
     let count = arg.parse::<u8>();
10
     match count {
13
     match count {
19
             Ok(())
22
             Ok(())
20
         },
23
         },
21
         Err(_) => {
24
         Err(_) => {
22
-            Err("Parse Failed".to_string())
25
+            Err("Failed to parse arguments. PIDs must be decimal.".to_string())
23
         },
26
         },
24
     }
27
     }
25
 }
28
 }
26
 
29
 
27
-pub fn fork_children(count: u8, to:u8, start_pid: i32) {
30
+
31
+/// Private function, which forks specified amount of processes (*count*) through recursion
32
+fn fork_children(count: u8, to:u8, start_pid: i32) {
28
     let pid = fork();
33
     let pid = fork();
29
     match pid {
34
     match pid {
30
         Ok(Child) => {
35
         Ok(Child) => {

Loading…
Cancel
Save