Implement the typical use of waitpid
This commit is contained in:
		
							parent
							
								
									e680a84a57
								
							
						
					
					
						commit
						3e726a5d0d
					
				
					 6 changed files with 146 additions and 101 deletions
				
			
		| 
						 | 
				
			
			@ -363,3 +363,27 @@ pub fn sched_yield() -> Result<usize> {
 | 
			
		|||
    unsafe { context::switch(); }
 | 
			
		||||
    Ok(0)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result<usize> {
 | 
			
		||||
    loop {
 | 
			
		||||
        {
 | 
			
		||||
            let mut exited = false;
 | 
			
		||||
 | 
			
		||||
            {
 | 
			
		||||
                let contexts = context::contexts();
 | 
			
		||||
                let context_lock = contexts.get(pid).ok_or(Error::NoProcess)?;
 | 
			
		||||
                let context = context_lock.read();
 | 
			
		||||
                if context.status == context::Status::Exited {
 | 
			
		||||
                    exited = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if exited {
 | 
			
		||||
                let mut contexts = context::contexts_mut();
 | 
			
		||||
                return contexts.remove(pid).ok_or(Error::NoProcess).and(Ok(pid));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        unsafe { context::switch(); }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue