Skip to content

Commit 9ebb50e

Browse files
committed
Document the PID argument in waitpid
1 parent d0628e1 commit 9ebb50e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/sys/wait.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ fn decode(pid : Pid, status: i32) -> WaitStatus {
215215
}
216216
}
217217

218+
/// Counterpart of the POSIX `waitpid` function
219+
/// It's best to use `nix::unistd::Pid` for passing the PID to this function
220+
///
221+
/// # Examples
222+
/// ```
223+
/// use std::process::Command;
224+
/// use nix::unistd::Pid;
225+
/// use nix::sys::{waitpid, WaitStatus};
226+
/// let child = Command::new("ls").spawn().unwrap();
227+
/// let pid = Pid::from_raw(child.id() as i32);
228+
/// match waitpid(pid, None) {
229+
/// Ok(WaitStatus::Exited(_, code)) => println!("Child exited with code {}", code),
230+
/// Ok(_) => println!("Other process exited, but not normally"),
231+
/// Err(_) => panic!("There was an error")
232+
/// }
233+
/// ```
218234
pub fn waitpid<P: Into<Option<Pid>>>(pid: P, options: Option<WaitPidFlag>) -> Result<WaitStatus> {
219235
use self::WaitStatus::*;
220236

0 commit comments

Comments
 (0)