fix wait4 not removing child
This commit is contained in:
parent
0437e81f36
commit
f846ba11f2
@ -20,8 +20,7 @@ pub fn do_exit(exit_status: i32) {
|
|||||||
current.status = Status::ZOMBIE;
|
current.status = Status::ZOMBIE;
|
||||||
|
|
||||||
// Update children
|
// Update children
|
||||||
for child_weak in ¤t.children {
|
for child_ref in current.get_children_iter() {
|
||||||
let child_ref = child_weak.upgrade().unwrap();
|
|
||||||
let mut child = child_ref.lock().unwrap();
|
let mut child = child_ref.lock().unwrap();
|
||||||
child.parent = Some(IDLE_PROCESS.clone());
|
child.parent = Some(IDLE_PROCESS.clone());
|
||||||
}
|
}
|
||||||
@ -69,8 +68,7 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
|
|||||||
let mut current = current_ref.lock().unwrap();
|
let mut current = current_ref.lock().unwrap();
|
||||||
|
|
||||||
let mut any_child_to_wait_for = false;
|
let mut any_child_to_wait_for = false;
|
||||||
for child_weak in current.get_children() {
|
for child_ref in current.get_children_iter() {
|
||||||
let child_ref = child_weak.upgrade().unwrap();
|
|
||||||
let child = child_ref.lock().unwrap();
|
let child = child_ref.lock().unwrap();
|
||||||
|
|
||||||
let may_wait_for = match child_filter {
|
let may_wait_for = match child_filter {
|
||||||
@ -82,8 +80,9 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return immediately as a child that we wait for has alreay exited
|
// Return immediately as a child that we wait for has already exited
|
||||||
if child.status == Status::ZOMBIE {
|
if child.status == Status::ZOMBIE {
|
||||||
|
process_table::remove(child.pid);
|
||||||
return Ok(child.pid);
|
return Ok(child.pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +106,7 @@ pub fn do_wait4(child_filter: &ChildProcessFilter, exit_status: &mut i32) -> Res
|
|||||||
let mut current = current_ref.lock().unwrap();
|
let mut current = current_ref.lock().unwrap();
|
||||||
let child_i = {
|
let child_i = {
|
||||||
let mut child_i_opt = None;
|
let mut child_i_opt = None;
|
||||||
for (child_i, child_weak) in current.children.iter().enumerate() {
|
for (child_i, child_ref) in current.get_children_iter().enumerate() {
|
||||||
let child_ref = child_weak.upgrade().unwrap();
|
|
||||||
let child = child_ref.lock().unwrap();
|
let child = child_ref.lock().unwrap();
|
||||||
if child.get_pid() != child_pid {
|
if child.get_pid() != child_pid {
|
||||||
continue;
|
continue;
|
||||||
|
@ -88,8 +88,10 @@ impl Process {
|
|||||||
pub fn get_parent(&self) -> &ProcessRef {
|
pub fn get_parent(&self) -> &ProcessRef {
|
||||||
self.parent.as_ref().unwrap()
|
self.parent.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
pub fn get_children(&self) -> &[ProcessWeakRef] {
|
pub fn get_children_iter(&self) -> impl Iterator<Item=ProcessRef> + '_ {
|
||||||
&self.children
|
self.children
|
||||||
|
.iter()
|
||||||
|
.filter_map(|child_weak| child_weak.upgrade())
|
||||||
}
|
}
|
||||||
pub fn change_cwd(&mut self, path: &str) {
|
pub fn change_cwd(&mut self, path: &str) {
|
||||||
if path.len() > 0 && path.as_bytes()[0] == b'/' {
|
if path.len() > 0 && path.as_bytes()[0] == b'/' {
|
||||||
|
Loading…
Reference in New Issue
Block a user