Merge pull request #78 from CL8192/forktree-fix

wait child exit in forktree
This commit is contained in:
chyyuu 2022-05-16 14:34:56 +08:00 committed by GitHub
commit d52256baa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}