Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d274e55

Browse files
committedJan 15, 2017
Auto merge of #39045 - redox-os:process_try_wait, r=brson
Add try_wait to Redox process This implements Process::try_wait on Redox
2 parents 4f0508a + b10e061 commit d274e55

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎src/libstd/sys/redox/process.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,18 @@ impl Process {
501501
self.status = Some(ExitStatus(status as i32));
502502
Ok(ExitStatus(status as i32))
503503
}
504+
505+
pub fn try_wait(&mut self) -> io::Result<ExitStatus> {
506+
if let Some(status) = self.status {
507+
return Ok(status)
508+
}
509+
let mut status = 0;
510+
let pid = cvt(syscall::waitpid(self.pid, &mut status, syscall::WNOHANG))?;
511+
if pid == 0 {
512+
Err(io::Error::from_raw_os_error(syscall::EWOULDBLOCK))
513+
} else {
514+
self.status = Some(ExitStatus(status as i32));
515+
Ok(ExitStatus(status as i32))
516+
}
517+
}
504518
}

0 commit comments

Comments
 (0)
Please sign in to comment.