pub fn check_state_nbl(&mut self) -> ProcessState {
        if self.state != ProcessState::Running {
            return self.state;
        }

        let wait_flags = libc::WNOHANG;
        let mut status_code: libc::c_int = 0;
        let status_code_ptr = &mut status_code as * mut libc::c_int;

        let ret = unsafe { libc::waitpid(self.pid.unwrap(), status_code_ptr, wait_flags) };
        libc_ret_to_result(ret, LibcSyscall::Waitpid).unwrap();

        // IDE doesn't find this functions but they exist

        // I'm not sure on this one..
        // maybe my assumption is wrong and "child process started"
        // is actually printed when the process is finished.
        // But this is not important for the problem here.

        // process didn't started running yet
        if ret == 0 {
            trace!("Child process not started yet");
            return self.state; // RUNNING
        } else if ret == self.pid.unwrap() {
            trace!("Child process started");
        }

        // returns true if the child terminated normally
        let exited_normally: bool = libc::WIFEXITED(status_code);
        // returns true if the child was terminated by signal
        let exited_by_signal: bool = libc::WIFSIGNALED(status_code);
        // exit code (0 = success, or > 1 = error)
        let exit_code: libc::c_int = libc::WEXITSTATUS(status_code);


        if exited_normally || exited_by_signal {
            self.exit_code.replace(exit_code);
            if exit_code == 0 {
                self.state = ProcessState::FinishedSuccess;
            } else {
                self.state = ProcessState::FinishedError(exit_code);
            }
        }

        self.state
    }
/// Check process state nonblocking from parent.
Check process state nonblocking from parent.
Check process state nonblocking from parent .
pub fn check_state_nbl(&mut self) -> ProcessState {
        if self.state != ProcessState::Running {
            return self.state;
        }
        let wait_flags = libc::WNOHANG;
        let mut status_code: libc::c_int = 0;
        let status_code_ptr = &mut status_code as * mut libc::c_int;
        let ret = unsafe { libc::waitpid(self.pid.unwrap(), status_code_ptr, wait_flags) };
        libc_ret_to_result(ret, LibcSyscall::Waitpid).unwrap();
        // IDE doesn't find this functions but they exist
        // I'm not sure on this one..
        // maybe my assumption is wrong and "child process started"
        // is actually printed when the process is finished.
        // But this is not important for the problem here.
        // process didn't started running yet
        if ret == 0 {
            trace!("Child process not started yet");
            return self.state; // RUNNING
        } else if ret == self.pid.unwrap() {
            trace!("Child process started");
        }
        // returns true if the child terminated normally
        let exited_normally: bool = libc::WIFEXITED(status_code);
        // returns true if the child was terminated by signal
        let exited_by_signal: bool = libc::WIFSIGNALED(status_code);
        // exit code (0 = success, or > 1 = error)
        let exit_code: libc::c_int = libc::WEXITSTATUS(status_code);
        if exited_normally || exited_by_signal {
            self.exit_code.replace(exit_code);
            if exit_code == 0 {
                self.state = ProcessState::FinishedSuccess;
            } else {
                self.state = ProcessState::FinishedError(exit_code);
            }
        }
        self.state
    }
pub fn check_state_nbl ( & mut self ) -> ProcessState { if self . state != ProcessState :: Running { return self . state ; } let wait_flags = libc :: WNOHANG ; let mut status_code : libc :: c_int = 0 ; let status_code_ptr = & mut status_code as * mut libc :: c_int ; let ret = unsafe { libc :: waitpid ( self . pid . unwrap ( ) , status_code_ptr , wait_flags ) } ; libc_ret_to_result ( ret , LibcSyscall :: Waitpid ) . unwrap ( ) ; // IDE doesn't find this functions but they exist // I'm not sure on this one.. // maybe my assumption is wrong and "child process started" // is actually printed when the process is finished. // But this is not important for the problem here. // process didn't started running yet if ret == 0 { trace ! ( " " ) ; return self . state ; // RUNNING } else if ret == self . pid . unwrap ( ) { trace ! ( " " ) ; } // returns true if the child terminated normally let exited_normally : bool = libc :: WIFEXITED ( status_code ) ; // returns true if the child was terminated by signal let exited_by_signal : bool = libc :: WIFSIGNALED ( status_code ) ; // exit code (0 = success, or > 1 = error) let exit_code : libc :: c_int = libc :: WEXITSTATUS ( status_code ) ; if exited_normally || exited_by_signal { self . exit_code . replace ( exit_code ) ; if exit_code == 0 { self . state = ProcessState :: FinishedSuccess ; } else { self . state = ProcessState :: FinishedError ( exit_code ) ; } } self . state }
Check process state nonblocking from parent.
Check process state nonblocking from parent .
&mut self