Pārlūkot izejas kodu

Commented pstree.rs.

themultiplexer 8 gadus atpakaļ
vecāks
revīzija
f97360b8ef
1 mainītis faili ar 7 papildinājumiem un 2 dzēšanām
  1. 7
    2
      hw5/task1/src/child/mod.rs

+ 7
- 2
hw5/task1/src/child/mod.rs Parādīt failu

@@ -5,6 +5,9 @@ use nix::unistd::ForkResult::{Child, Parent};
5 5
 
6 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 11
 pub fn run_childs(start_pid: i32, arg: &str) -> Result<(), String> {
9 12
     let count = arg.parse::<u8>();
10 13
     match count {
@@ -19,12 +22,14 @@ pub fn run_childs(start_pid: i32, arg: &str) -> Result<(), String> {
19 22
             Ok(())
20 23
         },
21 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 33
     let pid = fork();
29 34
     match pid {
30 35
         Ok(Child) => {

Notiek ielāde…
Atcelt
Saglabāt