Function nc::wait4

source ·
pub unsafe fn wait4(
    pid: pid_t,
    wstatus: Option<&mut i32>,
    options: i32,
    rusage: Option<&mut rusage_t>,
) -> Result<pid_t, Errno>
Expand description

Wait for process to change state.

§Examples

let pid = unsafe { nc::fork() };

match pid {
    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::wait4(-1, Some(&mut status), 0, None) };
        assert!(ret.is_ok());
        println!("status: {}", status);
        let exited_pid = ret.unwrap();
        assert_eq!(exited_pid, pid);
    }
}