summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys/wait.rs6
-rw-r--r--test/test_unistd.rs17
2 files changed, 22 insertions, 1 deletions
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index a6bccd8a..9252609b 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -16,7 +16,7 @@ bitflags!(
}
);
-#[derive(Clone, Copy)]
+#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum WaitStatus {
Exited(pid_t),
StillAlive
@@ -42,3 +42,7 @@ pub fn waitpid(pid: pid_t, options: Option<WaitPidFlag>) -> Result<WaitStatus> {
Ok(Exited(res))
}
}
+
+pub fn wait() -> Result<WaitStatus> {
+ waitpid(-1, None)
+}
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 50af197c..055c0c1a 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -30,6 +30,23 @@ fn test_fork_and_waitpid() {
}
#[test]
+fn test_wait() {
+ let pid = fork();
+ match pid {
+ Ok(Child) => {} // ignore child here
+ Ok(Parent(child_pid)) => {
+ let wait_status = wait();
+
+ // just assert that (any) one child returns with WaitStatus::Exited
+ assert_eq!(wait_status, Ok(WaitStatus::Exited(child_pid)));
+ },
+ // panic, fork should never fail unless there is a serious problem with the OS
+ Err(_) => panic!("Error: Fork Failed")
+ }
+}
+
+
+#[test]
fn test_getpid() {
let pid = getpid();
let ppid = getppid();