|
|
@@ -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(){
|