1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
extern crate libc;

use libc::pid_t;
use libc::c_int;

const WNOHANG : c_int = 0x00000001;

extern {
    pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t;
}

pub fn collect_zombies() {
    unsafe {
        while waitpid(-1, std::ptr::null_mut(), WNOHANG) > 0 {
        }
    }
}