Function base::sys::linux::reap_child

source ·
pub fn reap_child() -> Result<Pid>
Expand description

Reaps a child process that has terminated.

Returns Ok(pid) where pid is the process that was reaped or Ok(0) if none of the children have terminated. An Error is with errno == ECHILD if there are no children left to reap.

§Examples

Reaps all child processes until there are no terminated children to reap.

fn reap_children() {
    loop {
        match base::linux::reap_child() {
            Ok(0) => println!("no children ready to reap"),
            Ok(pid) => {
                println!("reaped {}", pid);
                continue
            },
            Err(e) if e.errno() == libc::ECHILD => println!("no children left"),
            Err(e) => println!("error reaping children: {}", e),
        }
        break
    }
}