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