Explorar el Código

Made zombie/mod.rs runnable. Works now.

Lorenz Bung hace 8 años
padre
commit
d4124d4dd0
Se han modificado 1 ficheros con 26 adiciones y 0 borrados
  1. 26
    0
      hw5/task1/src/zombie/mod.rs

+ 26
- 0
hw5/task1/src/zombie/mod.rs Ver fichero

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…
Cancelar
Guardar