//! Command execution module. //! use std::ffi::OsStr; use std::process::{Command,Child}; use std::io::Result; use libc::c_int; use libc::pid_t; use std::ptr; const WNOHANG: c_int = 0x00000001; extern { /// wait for a child process to stop or terminate. pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t; } /// Executes the given command. pub fn exec_cmd>(program: S, args: &[S]) -> Result { Command::new(program).args(args).spawn() } /// Collect all the zombies. There's no need to add another dependency for this /// since it's trivial to implement. /// /// See https://github.com/Kintaro/zombie for reference. pub fn collect_zombies() { unsafe { while waitpid(-1, ptr::null_mut(), WNOHANG) > 0 {} }; }