소스 검색

Made zombie/mod.rs runnable. Works now.

Lorenz Bung 8 년 전
부모
커밋
d4124d4dd0
1개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. 26
    0
      hw5/task1/src/zombie/mod.rs

+ 26
- 0
hw5/task1/src/zombie/mod.rs 파일 보기

@@ -0,0 +1,26 @@
1
+use std::process::Command;
2
+use std::{thread, time};
3
+use nix::sys::signal::*;
4
+use nix::unistd::{fork, ForkResult};
5
+
6
+pub fn run_zombie() {
7
+    match fork().expect("Fork failed") {
8
+
9
+        // In case this is the Parent process, kill the new child.
10
+        ForkResult::Parent{ child } => {
11
+            kill(child, SIGKILL).expect("Kill failed");
12
+        },
13
+
14
+        // In case this is the Child process, wait until killed.
15
+        ForkResult::Child => {
16
+            thread::sleep(
17
+                time::Duration::new(5000, 0) //Wait for a long time
18
+            );
19
+        }
20
+    }
21
+
22
+
23
+    let output = Command::new("ps").arg("t").output().expect("Error in run_zombie");
24
+
25
+    println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
26
+}

Loading…
취소
저장