mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 02:46:23 +04:00
wait child exit in forktree
This commit is contained in:
parent
9a95c7dcb4
commit
7c83dd49e7
@ -4,7 +4,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate user_lib;
|
extern crate user_lib;
|
||||||
|
|
||||||
use user_lib::{exit, fork, getpid, sleep, yield_};
|
use user_lib::{exit, fork, getpid, sleep, yield_, wait};
|
||||||
|
|
||||||
const DEPTH: usize = 4;
|
const DEPTH: usize = 4;
|
||||||
|
|
||||||
@ -21,18 +21,25 @@ fn fork_child(cur: &str, branch: char) {
|
|||||||
yield_();
|
yield_();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fork_tree(cur: &str) {
|
fn fork_tree(cur: &str) {
|
||||||
println!("pid{}: {}", getpid(), cur);
|
println!("pid{}: {}", getpid(), cur);
|
||||||
fork_child(cur, '0');
|
fork_child(cur, '0');
|
||||||
fork_child(cur, '1');
|
fork_child(cur, '1');
|
||||||
|
let mut exit_code: i32 = 0;
|
||||||
|
for _ in 0..2{
|
||||||
|
wait(&mut exit_code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn main() -> i32 {
|
pub fn main() -> i32 {
|
||||||
fork_tree("");
|
fork_tree("");
|
||||||
|
let mut exit_code: i32 = 0;
|
||||||
|
for _ in 0..2{
|
||||||
|
wait(&mut exit_code);
|
||||||
|
}
|
||||||
sleep(3000);
|
sleep(3000);
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user