|
|
@ -38,18 +38,22 @@ fn main() -> i32 {
|
|
|
|
panic!("Cannot find main!");
|
|
|
|
panic!("Cannot find main!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sys_waitpid如果传的是-1 则表示任何子进程退出都可以,
|
|
|
|
pub fn wait(exit_code: &mut i32) -> isize {
|
|
|
|
pub fn wait(exit_code: &mut i32) -> isize {
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
match sys_waitpid(-1, exit_code as *mut _) {
|
|
|
|
match sys_waitpid(-1, exit_code as *mut _) {
|
|
|
|
|
|
|
|
// 如果返回-2, 说明还没有僵尸进程, 那就下一轮loop循环继续等待
|
|
|
|
-2 => {
|
|
|
|
-2 => {
|
|
|
|
sys_yield();
|
|
|
|
sys_yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果返回 -1 说明有任意进程结束
|
|
|
|
// -1 or a real pid
|
|
|
|
// -1 or a real pid
|
|
|
|
exit_pid => return exit_pid,
|
|
|
|
exit_pid => return exit_pid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 只检测指定pid的进程是否结束
|
|
|
|
pub fn waitpid(pid: usize, exit_code: &mut i32) -> isize {
|
|
|
|
pub fn waitpid(pid: usize, exit_code: &mut i32) -> isize {
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
match sys_waitpid(pid as isize, exit_code as *mut _) {
|
|
|
|
match sys_waitpid(pid as isize, exit_code as *mut _) {
|
|
|
|