Function nc::waitpid

source ·
pub unsafe fn waitpid(
    pid: pid_t,
    status: &mut i32,
    options: i32
) -> Result<pid_t, Errno>
Expand description

Wait for process to change state.

§Example

let ret = unsafe { nc::fork() };
match ret {
    Err(errno) => {
        eprintln!("fork() error: {}", nc::strerror(errno));
        unsafe { nc::exit(1) };
    }
    Ok(0) => println!("[child] pid is: {}", unsafe { nc::getpid() }),
    Ok(pid) => {
        let mut status = 0;
        let ret = unsafe { nc::waitpid(pid, &mut status, 0) };
        assert!(ret.is_ok());
        let exited_pid = ret.unwrap();
        assert_eq!(exited_pid, pid);
    }
}