Python os.WIFSTOPPED() Examples

The following are code examples for showing how to use os.WIFSTOPPED(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: NiujiaoDebugger   Author: MrSrc   File: subprocess.py    GNU General Public License v3.0 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 2
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: subprocess.py    GNU General Public License v2.0 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 3
Project: setup   Author: mindbender-studio   File: subprocess.py    MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 4
Project: pxf   Author: greenplum-db   File: pexpect.py    Apache License 2.0 6 votes vote down vote up
def wait(self):
        """This waits until the child exits. This is a blocking call.
            This will not read any data from the child, so this will block forever
            if the child has unread output and has terminated. In other words, the child
            may have printed output then called exit(); but, technically, the child is
            still alive until its output is read.
        """
        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect ('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED (status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED (status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED (status):
            raise ExceptionPexpect ('Wait was called for a child process that is stopped. This is not supported. Is some other process attempting job control with our child pid?')
        return self.exitstatus 
Example 5
Project: docker   Author: getavalon   File: subprocess.py    MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 6
Project: spichi   Author: ifkite   File: autoreload.py    MIT License 6 votes vote down vote up
def wait_child(pid):
    while True:
        try:
            # wait for child process
            wpid, sts = os.waitpid(pid, 0)
        except KeyboardInterrupt:
            # handle exceptions when parent is waiting
            handle_parent_exit(pid)

        # if child process stopped
        if os.WIFSTOPPED(sts):
            continue
        # if receive keybord interuption or kill signal
        elif os.WIFSIGNALED(sts):
            return sts
        # seems not work
        elif os.WIFEXITED(sts):
            return sts
        else:
            raise "Not stopped, signaled or exited???" 
Example 7
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: subprocess.py    GNU General Public License v3.0 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 8
Project: cells   Author: AlesTsurko   File: subprocess.py    MIT License 6 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            """All callers to this function MUST hold self._waitpid_lock."""
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise SubprocessError("Unknown child exit status!") 
Example 9
Project: pointbreak   Author: tonysimpson   File: debugger.py    MIT License 6 votes vote down vote up
def _trigger_status_events(self, status, single_stepped=False):
        """Take a waitpid status and returns an Event. None if we don't want to surface the event to the user.
        """
        event = None
        if os.WIFSTOPPED(status):
            sig = os.WSTOPSIG(status)
            if sig == signal.SIGTRAP:
                event = self._trigger_trap_event(single_stepped)
            else:
                self._cont_signal = sig
                event = Event(EVENT_NAME_STOPPED, signal=sig)
        elif os.WIFEXITED(status):
            self._dead = True
            exit_status = os.WEXITSTATUS(status)
            event = Event(EVENT_NAME_EXITED, status=exit_status)
        elif os.WIFSIGNALED(status):
            self._dead = True
            sig = os.WTERMSIG(status)
            event = Event(EVENT_NAME_TERMINATED, signal=sig)
        if event is not None:
            self._events.append(event) 
Example 10
Project: pointbreak   Author: tonysimpson   File: debugger.py    MIT License 6 votes vote down vote up
def _step_over_active_trap(self, timeout=None):
        trap = self._active_trap
        if trap is not None:
            if trap.address == self.registers.rip:
                if trap.is_debugger_inserted():
                    self._single_step()
                    status = self._wait(timeout=timeout)
                    # do events but ignore the trap caused by single step
                    if not (os.WIFSTOPPED(status) and (os.WSTOPSIG(status) == signal.SIGTRAP)):
                        self._trigger_status_events(status)
                else:
                    #just skip over the breakpoint
                    self.registers.rip += 1
                    self.save_registers()
            trap.restore(self)
            self._active_trap = None 
Example 11
Project: Repobot   Author: Desgard   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 12
Project: vagrant-prometheus-lab   Author: alexclear   File: parent.py    MIT License 5 votes vote down vote up
def wstatus_to_str(status):
    """
    Parse and format a :func:`os.waitpid` exit status.
    """
    if os.WIFEXITED(status):
        return 'exited with return code %d' % (os.WEXITSTATUS(status),)
    if os.WIFSIGNALED(status):
        n = os.WTERMSIG(status)
        return 'exited due to signal %d (%s)' % (n, SIGNAL_BY_NUM.get(n))
    if os.WIFSTOPPED(status):
        n = os.WSTOPSIG(status)
        return 'stopped due to signal %d (%s)' % (n, SIGNAL_BY_NUM.get(n))
    return 'unknown wait status (%d)' % (status,) 
Example 13
Project: ironpython2   Author: IronLanguages   File: subprocess.py    Apache License 2.0 5 votes vote down vote up
def _handle_exitstatus(self, sts, _WIFSIGNALED=os.WIFSIGNALED,
                _WTERMSIG=os.WTERMSIG, _WIFEXITED=os.WIFEXITED,
                _WEXITSTATUS=os.WEXITSTATUS, _WIFSTOPPED=os.WIFSTOPPED,
                _WSTOPSIG=os.WSTOPSIG):
            # This method is called (indirectly) by __del__, so it cannot
            # refer to anything outside of its local scope.
            if _WIFSIGNALED(sts):
                self.returncode = -_WTERMSIG(sts)
            elif _WIFEXITED(sts):
                self.returncode = _WEXITSTATUS(sts)
            elif _WIFSTOPPED(sts):
                self.returncode = -_WSTOPSIG(sts)
            else:
                # Should never happen
                raise RuntimeError("Unknown child exit status!") 
Example 14
Project: Computable   Author: ktraunmueller   File: _pexpect.py    MIT License 5 votes vote down vote up
def wait(self):

        """This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(); but, technically, the child
        is still alive until its output is read. """

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect ('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED (status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED (status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED (status):
            raise ExceptionPexpect ('Wait was called for a child process that is stopped. This is not supported. Is some other process attempting job control with our child pid?')
        return self.exitstatus 
Example 15
Project: pipenv   Author: pypa   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 16
Project: pycopia   Author: kdart   File: exitstatus.py    Apache License 2.0 5 votes vote down vote up
def __init__(self, cmdline, sts):
        self.cmdline = cmdline
        if os.WIFEXITED(sts):
            self.state = 1
            self._status = self._es = os.WEXITSTATUS(sts)

        elif os.WIFSTOPPED(sts):
            self.state = 2
            self._status = self.stopsig = os.WSTOPSIG(sts)

        elif os.WIFSIGNALED(sts):
            self.state = 3
            self._status = self.termsig = os.WTERMSIG(sts) 
Example 17
Project: lunlumo   Author: nasaWelder   File: ptyprocess.py    GNU General Public License v3.0 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 18
Project: ptracer   Author: pinterest   File: _defs_linux.py    Apache License 2.0 5 votes vote down vote up
def WPTRACEEVENT(status):
    if os.WIFSTOPPED(status):
        stopsig = os.WSTOPSIG(status)
        if stopsig == signal.SIGTRAP:
            return status >> 16

    return 0 
Example 19
Project: url_shortener   Author: martydill   File: _pexpect.py    MIT License 5 votes vote down vote up
def wait(self):

        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise ExceptionPexpect('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 20
Project: emulated-sdn-application   Author: tranlyvu   File: process.py    Apache License 2.0 5 votes vote down vote up
def status_msg(status):
    """Given 'status', which is a process status in the form reported by
    waitpid(2) and returned by process_status(), returns a string describing
    how the process terminated."""
    if os.WIFEXITED(status):
        s = "exit status %d" % os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        s = _signal_status_msg("killed", os.WTERMSIG(status))
    elif os.WIFSTOPPED(status):
        s = _signal_status_msg("stopped", os.WSTOPSIG(status))
    else:
        s = "terminated abnormally (%x)" % status
    if os.WCOREDUMP(status):
        s += ", core dumped"
    return s 
Example 21
Project: pipenv-sublime   Author: Zheaoli   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 22
Project: pxf   Author: greenplum-db   File: gpsubprocess.py    Apache License 2.0 5 votes vote down vote up
def _check_status(self):
        terminated=False
        """Another possibility for the below line would be to try and capture
        rusage information.  Perhaps that type of call would be an external
        method for users to check on status:        
        (pid, status, rusage)=os.wait4(self.pid, os.WNOHANG)
        """
        (pid,status)=os.waitpid(self.pid, os.WNOHANG)
        

        if pid == 0:
            #means we are still in progress
            return

        exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED (status):            
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            terminated = True
        elif os.WIFSIGNALED (status):
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            terminated = True
        elif os.WIFSTOPPED (status):
            raise Exception('Wait was called for a child process that is stopped.\
                             This is not supported. Is some other process attempting\
                             job control with our child pid?')

        self._handle_exitstatus(status)

        return terminated 
Example 23
Project: xtools   Author: liuzl   File: pexpect.py    GNU General Public License v3.0 5 votes vote down vote up
def wait(self):

        """This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(); but, technically, the child
        is still alive until its output is read. """

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect ('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED (status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED (status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED (status):
            raise ExceptionPexpect ('Wait was called for a child process that is stopped. This is not supported. Is some other process attempting job control with our child pid?')
        return self.exitstatus 
Example 24
Project: ssh-tunnel   Author: aalku   File: __init__.py    MIT License 5 votes vote down vote up
def wait(self):

        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise ExceptionPexpect('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 25
Project: Ryu-Qos   Author: xiaobinglu   File: process.py    Apache License 2.0 5 votes vote down vote up
def status_msg(status):
    """Given 'status', which is a process status in the form reported by
    waitpid(2) and returned by process_status(), returns a string describing
    how the process terminated."""
    if os.WIFEXITED(status):
        s = "exit status %d" % os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        s = _signal_status_msg("killed", os.WTERMSIG(status))
    elif os.WIFSTOPPED(status):
        s = _signal_status_msg("stopped", os.WSTOPSIG(status))
    else:
        s = "terminated abnormally (%x)" % status
    if os.WCOREDUMP(status):
        s += ", core dumped"
    return s 
Example 26
Project: winpexpect   Author: geertj   File: pexpect.py    MIT License 5 votes vote down vote up
def wait(self):

        """This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(); but, technically, the child
        is still alive until its output is read. """

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            raise ExceptionPexpect ('Cannot wait for dead child process.')
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED (status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED (status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED (status):
            raise ExceptionPexpect ('Wait was called for a child process that is stopped. This is not supported. Is some other process attempting job control with our child pid?')
        return self.exitstatus 
Example 27
Project: boofuzz-modbus   Author: youngcraft   File: process_monitor_unix.py    Apache License 2.0 5 votes vote down vote up
def post_send(self):
        """
        This routine is called after the fuzzer transmits a test case and returns the status of the target.

        @rtype:  bool
        @return: Return True if the target is still active, False otherwise.
        """

        if not self.dbg.is_alive():
            exit_status = self.dbg.get_exit_status()
            rec_file = open(self.crash_bin, 'a')
            if os.WCOREDUMP(exit_status):
                reason = 'Segmentation fault'
            elif os.WIFSTOPPED(exit_status):
                reason = 'Stopped with signal ' + str(os.WTERMSIG(exit_status))
            elif os.WIFSIGNALED(exit_status):
                reason = 'Terminated with signal ' + str(os.WTERMSIG(exit_status))
            elif os.WIFEXITED(exit_status):
                reason = 'Exit with code - ' + str(os.WEXITSTATUS(exit_status))
            else:
                reason = 'Process died for unknown reason'

            self.last_synopsis = '[%s] Crash : Test - %d Reason - %s\n' % (
                time.strftime("%I:%M.%S"),
                self.test_number,
                reason
            )
            rec_file.write(self.last_synopsis)
            rec_file.close()

            if self.coredump_dir is not None:
                dest = os.path.join(self.coredump_dir, str(self.test_number))
                src = self._get_coredump_path()

                if src is not None:
                    self.log("moving core dump %s -> %s" % (src, dest))
                    os.rename(src, dest)

        return self.dbg.is_alive() 
Example 28
Project: debug-visualizer   Author: Kobzol   File: programrunner.py    GNU General Public License v3.0 5 votes vote down vote up
def _handle_child_status(self, status):
        if os.WIFSTOPPED(status):
            self._on_stop(status)
        elif os.WIFEXITED(status):
            self.on_signal.notify(ProcessState.Exited,
                                  os.WTERMSIG(status),
                                  os.WEXITSTATUS(status))
            raise ProcessExitException() 
Example 29
Project: cryptobot   Author: nbiederbeck   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 30
Project: cryptobot   Author: nbiederbeck   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 31
Project: my_hass_config   Author: ivencooli   File: ptyprocess.py    MIT License 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 32
Project: tigerfix   Author: nicekingwei   File: fix.py    GNU General Public License v3.0 5 votes vote down vote up
def wait_stopped(pid):
    while True:
        _, status = os.waitpid(pid, 0)
        if os.WIFSTOPPED(status):
            break 
Example 33
Project: tigerfix   Author: nicekingwei   File: fix.py    GNU General Public License v3.0 5 votes vote down vote up
def wait_trap(pid):
    while True:
        _, status = os.waitpid(pid, 0)
        if os.WIFSTOPPED(status) and os.WSTOPSIG(status) == signal.SIGTRAP:
            break 
Example 34
Project: CUP   Author: baidu   File: ptyprocess.py    Apache License 2.0 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 35
Project: mitogen   Author: dw   File: fork.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _convert_exit_status(status):
    """
    Convert a :func:`os.waitpid`-style exit status to a :mod:`subprocess` style
    exit status.
    """
    if os.WIFEXITED(status):
        return os.WEXITSTATUS(status)
    elif os.WIFSIGNALED(status):
        return -os.WTERMSIG(status)
    elif os.WIFSTOPPED(status):
        return -os.WSTOPSIG(status) 
Example 36
Project: greengrass-ehealth-workshop   Author: InternetOfHealthcare   File: ptyprocess.py    Apache License 2.0 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 37
Project: greengrass-ehealth-workshop   Author: InternetOfHealthcare   File: ptyprocess.py    Apache License 2.0 5 votes vote down vote up
def wait(self):
        '''This waits until the child exits. This is a blocking call. This will
        not read any data from the child, so this will block forever if the
        child has unread output and has terminated. In other words, the child
        may have printed output then called exit(), but, the child is
        technically still alive until its output is read by the parent. '''

        if self.isalive():
            pid, status = os.waitpid(self.pid, 0)
        else:
            return self.exitstatus
        self.exitstatus = os.WEXITSTATUS(status)
        if os.WIFEXITED(status):
            self.status = status
            self.exitstatus = os.WEXITSTATUS(status)
            self.signalstatus = None
            self.terminated = True
        elif os.WIFSIGNALED(status):
            self.status = status
            self.exitstatus = None
            self.signalstatus = os.WTERMSIG(status)
            self.terminated = True
        elif os.WIFSTOPPED(status):  # pragma: no cover
            # You can't call wait() on a child process in the stopped state.
            raise PtyProcessError('Called wait() on a stopped child ' +
                    'process. This is not supported. Is some other ' +
                    'process attempting job control with our child pid?')
        return self.exitstatus 
Example 38
Project: afl-utils   Author: rc0r   File: AflThread.py    Apache License 2.0 4 votes vote down vote up
def run(self):
        while not self.exit:
            self.in_queue_lock.acquire()
            if not self.in_queue.empty():
                cs = self.in_queue.get()
                self.in_queue_lock.release()

                cmd = self.target_cmd.replace("@@", os.path.abspath(cs))
                cs_fd = open(os.path.abspath(cs))
                try:
                    if afl_utils.afl_collect.stdin_mode(self.target_cmd):
                        v = subprocess.call(cmd.split(), stdin=cs_fd, stderr=subprocess.DEVNULL,
                                            stdout=subprocess.DEVNULL, timeout=self.timeout_secs)
                    else:
                        v = subprocess.call(cmd.split(), stderr=subprocess.DEVNULL,
                                            stdout=subprocess.DEVNULL, timeout=self.timeout_secs)
                    # check if process was terminated/stopped by signal
                    if not os.WIFSIGNALED(v) and not os.WIFSTOPPED(v):
                        self.out_queue_lock.acquire()
                        self.out_queue.put((cs, 'invalid'))
                        self.out_queue_lock.release()
                    else:
                        # need extension (add uninteresting signals):
                        # following signals don't indicate hard crashes: 1
                        # os.WTERMSIG(v) ?= v & 0x7f ???
                        if (os.WTERMSIG(v) or os.WSTOPSIG(v)) in [1]:
                            self.out_queue_lock.acquire()
                            self.out_queue.put((cs, 'invalid'))
                            self.out_queue_lock.release()
                        # debug
                        # else:
                        #     if os.WIFSIGNALED(v):
                        #         print("%s: sig: %d (%d)" % (cs, os.WTERMSIG(v), v))
                        #     elif os.WIFSTOPPED(v):
                        #         print("%s: sig: %d (%d)" % (cs, os.WSTOPSIG(v), v))
                except subprocess.TimeoutExpired:
                    self.out_queue_lock.acquire()
                    self.out_queue.put((cs, 'timeout'))
                    self.out_queue_lock.release()
                except Exception:
                    pass
                cs_fd.close()
            else:
                self.in_queue_lock.release()
                self.exit = True 
Example 39
Project: ptracer   Author: pinterest   File: ptrace.py    Apache License 2.0 4 votes vote down vote up
def _wait_for_trace_stop(pid):
    try:
        # First, check if the tracee is already stopped.
        siginfo = getsiginfo(pid)
    except OSError as e:
        if e.errno == errno.ESRCH:
            # The tracee is still running, so we'll wait
            pass
        else:
            raise
    else:
        # Normally, PTRACE_ATTACH will send a SIGSTOP to the tracee,
        # which we will see here.  However, on some kernels the actual
        # signal may sometimes be SIGTRAP, and that seems to happen
        # when the previous tracer had died without calling PTRACE_DETACH
        # on this process first.  In this case, we need to restart the process
        # and wait for the real SIGSTOP.
        if siginfo.si_signo == signal.SIGTRAP:
            cont(pid, siginfo.si_signo)
        elif is_stop_signal(siginfo.si_signo):
            return
        else:
            raise OSError('traced process has stopped with an unexpected '
                          'signal {}'.format(siginfo.si_signo))

    pid, status = wait(pid)

    if os.WIFEXITED(status):
        raise OSError('traced process {} has exited with exit code {}'.format(
            pid, os.WEXITSTATUS(status)))

    elif os.WIFSIGNALED(status):
        raise OSError('traced process {} has been killed by '
                      'the {} signal {}'.format(pid, os.WTERMSIG(status)))

    if not os.WIFSTOPPED(status):
        raise OSError('waitpid({}) returned an unexpected status {}'.format(
            pid, hex(status)))

    stopsig = os.WSTOPSIG(status)
    if stopsig != signal.SIGSTOP:
        raise OSError('waitpid({}) returned an unexpected status {}'.format(
            pid, hex(status)))