Kaynağa Gözat

Imported everything. Ready to develop fork logic.

Joshua Rutschmann 8 yıl önce
ebeveyn
işleme
846f2ee581
2 değiştirilmiş dosya ile 41 ekleme ve 1 silme
  1. 1
    0
      hw6/task1/Cargo.toml
  2. 40
    1
      hw6/task1/src/main.rs

+ 1
- 0
hw6/task1/Cargo.toml Dosyayı Görüntüle

@@ -4,3 +4,4 @@ version = "0.1.0"
4 4
 authors = ["Joshua Rutschmann <joshua.rutschmann@gmx.de>"]
5 5
 
6 6
 [dependencies]
7
+nix = "0.9.0"

+ 40
- 1
hw6/task1/src/main.rs Dosyayı Görüntüle

@@ -1,5 +1,44 @@
1
+use std::env::args;
2
+use std::process;
3
+
4
+extern crate nix;
5
+
6
+use nix::unistd::{fork, getpid};
7
+use nix::sys::wait::wait;
8
+use nix::sys::wait::WaitStatus;
9
+use nix::unistd::ForkResult::{Child, Parent};
10
+
1 11
 fn main() {
2
-    println!("Hello, world!");
12
+
13
+ let arguments: Vec<String> = args().collect();
14
+
15
+    if arguments.len() != 0 {
16
+   
17
+
18
+    let pid = fork();
19
+    match pid {
20
+        Ok(Child) => {
21
+            println!("hello, I am child (pid:{})", getpid());
22
+        }
23
+
24
+        Ok(Parent { child }) => {
25
+            if let Ok(ws) = wait() {
26
+                if let WaitStatus::Exited(child_pid, exit_code) = ws {
27
+                
28
+                }
29
+            }
30
+        }
31
+
32
+        Err(_) => {}
33
+    }
34
+
35
+
36
+
37
+    } else {
38
+        println!("Correct usage: number number <number> ...");
39
+        process::exit(1)
40
+    }
41
+
3 42
 }
4 43
 
5 44
 fn concatenate_strings(){

Loading…
İptal
Kaydet