summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index de3b0490..268c9994 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -200,14 +200,19 @@ impl ForkResult {
/// be created that are identical with the exception of their pid and the
/// return value of this function. As an example:
///
-/// ```no_run
-/// use nix::unistd::{fork, ForkResult};
+/// ```
+/// use nix::{sys::wait::waitpid,unistd::{fork, ForkResult, write}};
///
/// match unsafe{fork()} {
/// Ok(ForkResult::Parent { child, .. }) => {
/// println!("Continuing execution in parent process, new child has pid: {}", child);
+/// waitpid(child, None).unwrap();
+/// }
+/// Ok(ForkResult::Child) => {
+/// // Unsafe to use `println!` (or `unwrap`) here. See Safety.
+/// write(libc::STDOUT_FILENO, "I'm a new child process\n".as_bytes()).ok();
+/// unsafe { libc::_exit(0) };
/// }
-/// Ok(ForkResult::Child) => println!("I'm a new child process"),
/// Err(_) => println!("Fork failed"),
/// }
/// ```