mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
Merge pull request #78 from CL8192/forktree-fix
wait child exit in forktree
This commit is contained in:
commit
d52256baa9
@ -4,7 +4,7 @@
|
||||
#[macro_use]
|
||||
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;
|
||||
|
||||
@ -21,18 +21,25 @@ fn fork_child(cur: &str, branch: char) {
|
||||
yield_();
|
||||
exit(0);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fn fork_tree(cur: &str) {
|
||||
println!("pid{}: {}", getpid(), cur);
|
||||
fork_child(cur, '0');
|
||||
fork_child(cur, '1');
|
||||
let mut exit_code: i32 = 0;
|
||||
for _ in 0..2{
|
||||
wait(&mut exit_code);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
fork_tree("");
|
||||
let mut exit_code: i32 = 0;
|
||||
for _ in 0..2{
|
||||
wait(&mut exit_code);
|
||||
}
|
||||
sleep(3000);
|
||||
0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user