Python signal.SIGSTOP Examples

The following are 30 code examples for showing how to use signal.SIGSTOP(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module signal , or try the search function .

Example 1
Project: psutil   Author: giampaolo   File: test_process.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_wait_stopped(self):
        p = self.spawn_psproc()
        if POSIX:
            # Test waitpid() + WIFSTOPPED and WIFCONTINUED.
            # Note: if a process is stopped it ignores SIGTERM.
            p.send_signal(signal.SIGSTOP)
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.send_signal(signal.SIGCONT)
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.send_signal(signal.SIGTERM)
            self.assertEqual(p.wait(), -signal.SIGTERM)
            self.assertEqual(p.wait(), -signal.SIGTERM)
        else:
            p.suspend()
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.resume()
            self.assertRaises(psutil.TimeoutExpired, p.wait, timeout=0.001)
            p.terminate()
            self.assertEqual(p.wait(), signal.SIGTERM)
            self.assertEqual(p.wait(), signal.SIGTERM) 
Example 2
Project: judge-server   Author: DMOJ   File: tracer.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def _shocker_thread(self):
        # On Linux, ignored signals still cause a notification under ptrace.
        # Hence, we use SIGWINCH, harmless and ignored signal to make wait4 return
        # pt_process::monitor, causing time to be updated.
        # On FreeBSD, a signal must not be ignored in order for wait4 to return.
        # Hence, we swallow SIGSTOP, which should never be used anyway, and use it
        # force an update.
        wake_signal = signal.SIGSTOP if 'freebsd' in sys.platform else signal.SIGWINCH
        self._spawned_or_errored.wait()

        while not self._died.wait(1):
            if self.execution_time > self._time or self.wall_clock_time > self._wall_time:
                log.warning('Shocker activated and killed %d', self.pid)
                self.kill()
                self._is_tle = True
                break
            try:
                os.killpg(self.pid, wake_signal)
            except OSError:
                pass 
Example 3
Project: Safejumper-for-Desktop   Author: proxysh   File: tkconch.py    License: GNU General Public License v2.0 6 votes vote down vote up
def handleInput(self, char):
        #log.msg('handling %s' % repr(char))
        if char in ('\n', '\r'):
            self.escapeMode = 1
            self.write(char)
        elif self.escapeMode == 1 and char == options['escape']:
            self.escapeMode = 2
        elif self.escapeMode == 2:
            self.escapeMode = 1 # so we can chain escapes together
            if char == '.': # disconnect
                log.msg('disconnecting from escape')
                reactor.stop()
                return
            elif char == '\x1a': # ^Z, suspend
                # following line courtesy of Erwin@freenode
                os.kill(os.getpid(), signal.SIGSTOP)
                return
            elif char == 'R': # rekey connection
                log.msg('rekeying connection')
                self.conn.transport.sendKexInit()
                return
            self.write('~' + char)
        else:
            self.escapeMode = 0
            self.write(char) 
Example 4
Project: memorpy   Author: n1nj4sec   File: LinProcess.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _ptrace(self, attach):
        op = ctypes.c_int(PTRACE_ATTACH if attach else PTRACE_DETACH)
        c_pid = c_pid_t(self.pid)
        null = ctypes.c_void_p()

        if not attach:
            os.kill(self.pid, signal.SIGSTOP)
            os.waitpid(self.pid, 0)

        err = c_ptrace(op, c_pid, null, null)

        if not attach:
            os.kill(self.pid, signal.SIGCONT)

        if err != 0:
            raise OSError("%s: %s"%(
                'PTRACE_ATTACH' if attach else 'PTRACE_DETACH',
                errno.errorcode.get(ctypes.get_errno(), 'UNKNOWN')
            )) 
Example 5
Project: pychess   Author: pychess   File: glib_events.py    License: GNU General Public License v3.0 6 votes vote down vote up
def add_signal_handler(self, sig, callback, *args):
            self.remove_signal_handler(sig)

            s = GLib.unix_signal_source_new(sig)
            if s is None:
                # Show custom error messages for signal that are uncatchable
                if sig == signal.SIGKILL:
                    raise RuntimeError("cannot catch SIGKILL")
                elif sig == signal.SIGSTOP:
                    raise RuntimeError("cannot catch SIGSTOP")
                else:
                    raise ValueError("signal not supported")

            assert sig not in self._sighandlers

            self._sighandlers[sig] = GLibHandle(
                loop=self,
                source=s,
                repeat=True,
                callback=callback,
                args=args) 
Example 6
Project: learn_python3_spider   Author: wistbean   File: tkconch.py    License: MIT License 6 votes vote down vote up
def handleInput(self, char):
        #log.msg('handling %s' % repr(char))
        if char in ('\n', '\r'):
            self.escapeMode = 1
            self.write(char)
        elif self.escapeMode == 1 and char == options['escape']:
            self.escapeMode = 2
        elif self.escapeMode == 2:
            self.escapeMode = 1 # so we can chain escapes together
            if char == '.': # disconnect
                log.msg('disconnecting from escape')
                reactor.stop()
                return
            elif char == '\x1a': # ^Z, suspend
                # following line courtesy of Erwin@freenode
                os.kill(os.getpid(), signal.SIGSTOP)
                return
            elif char == 'R': # rekey connection
                log.msg('rekeying connection')
                self.conn.transport.sendKexInit()
                return
            self.write('~' + char)
        else:
            self.escapeMode = 0
            self.write(char) 
Example 7
Project: python-afl   Author: jwilk   File: test_loop.py    License: MIT License 6 votes vote down vote up
def _test_persistent(n, *args, **kwargs):
    os.environ['PYTHON_AFL_PERSISTENT'] = '1'
    n_max = 1000
    k = [0]
    def kill(pid, sig):
        assert_equal(pid, os.getpid())
        assert_equal(sig, signal.SIGSTOP)
        k[0] += 1
    os.kill = kill
    x = 0
    while afl.loop(*args, **kwargs):
        x += 1
        if x == n_max:
            break
    if n is None:
        n = n_max
    assert_equal(x, n)
    assert_equal(k[0], n - 1) 
Example 8
Project: TikZ   Author: ellisk42   File: timeshare.py    License: GNU General Public License v3.0 6 votes vote down vote up
def execute(self,dt):
        if self.finished: return "finished"
        if not self.running:
            self.process = Process(target = executeInProcessGroup, args = (self,))
            self.process.start()
            print "timeshare child PID:",self.process.pid
            os.setpgid(self.process.pid,self.process.pid)
            print "timeshare process group",os.getpgid(self.process.pid)
            assert os.getpgid(self.process.pid) == self.process.pid
            print "my process group",os.getpgrp(),"which should be",os.getpgid(0)
            assert os.getpgid(self.process.pid) != os.getpgid(0)
            self.running = True
        else:
            os.killpg(self.process.pid, signal.SIGCONT)
        
        self.process.join(dt)
        if self.process.is_alive():
            os.killpg(self.process.pid, signal.SIGSTOP)
            return "still running"
        else:
            self.finished = True
            return self.q.get() 
Example 9
Project: python-for-android   Author: kuri65536   File: tkconch.py    License: Apache License 2.0 6 votes vote down vote up
def handleInput(self, char):
        #log.msg('handling %s' % repr(char))
        if char in ('\n', '\r'):
            self.escapeMode = 1
            self.write(char)
        elif self.escapeMode == 1 and char == options['escape']:
            self.escapeMode = 2
        elif self.escapeMode == 2:
            self.escapeMode = 1 # so we can chain escapes together
            if char == '.': # disconnect
                log.msg('disconnecting from escape')
                reactor.stop()
                return
            elif char == '\x1a': # ^Z, suspend
                # following line courtesy of Erwin@freenode
                os.kill(os.getpid(), signal.SIGSTOP)
                return
            elif char == 'R': # rekey connection
                log.msg('rekeying connection')
                self.conn.transport.sendKexInit()
                return
            self.write('~' + char)
        else:
            self.escapeMode = 0
            self.write(char) 
Example 10
Project: darkc0de-old-stuff   Author: tuwid   File: process.py    License: GNU General Public License v3.0 6 votes vote down vote up
def waitExit(self):
        debug("Wait %s exit" % self)
        while True:
            # Wait for any process signal
            event = self.waitEvent()
            event_cls = event.__class__

            # Process exited: we are done
            if event_cls == ProcessExit:
                debug(str(event))
                return

            # Event different than a signal? Raise an exception
            if event_cls != ProcessSignal:
                raise event

            # Send the signal to the process
            signum = event.signum
            if signum not in (SIGTRAP, SIGSTOP):
                self.cont(signum)
            else:
                self.cont() 
Example 11
Project: BitTorrent   Author: kenorb-contrib   File: tkconch.py    License: GNU General Public License v3.0 6 votes vote down vote up
def handleInput(self, char):
        #log.msg('handling %s' % repr(char))
        if char in ('\n', '\r'):
            self.escapeMode = 1
            self.write(char)
        elif self.escapeMode == 1 and char == options['escape']:
            self.escapeMode = 2
        elif self.escapeMode == 2:
            self.escapeMode = 1 # so we can chain escapes together
            if char == '.': # disconnect
                log.msg('disconnecting from escape')
                reactor.stop()
                return
            elif char == '\x1a': # ^Z, suspend
                # following line courtesy of Erwin@freenode
                os.kill(os.getpid(), signal.SIGSTOP)
                return
            elif char == 'R': # rekey connection
                log.msg('rekeying connection')
                self.conn.transport.sendKexInit()
                return
            self.write('~' + char)
        else:
            self.escapeMode = 0
            self.write(char) 
Example 12
Project: temci   Author: parttimenerd   File: run_driver_plugin.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setup(self):
        self.parse_processes()
        for proc in self._processes.values():
            if proc["pid"] == os.getpid():
                continue
            if any(proc["comm"].startswith(pref) for pref in self.misc_settings["comm_prefixes_ignored"]):
                continue
            if proc["nice"] == "-" or int(proc["nice"]) < self.misc_settings["min_nice"]:
                continue
            suffixes = self.misc_settings["subtree_suffixes"]
            if any(proc["comm"].startswith(pref) for pref in self.misc_settings["comm_prefixes"]) or \
                    proc["pid"] >= self.misc_settings["min_id"] or \
                    any(any(pcomm.endswith(suff) for suff in suffixes) for pcomm in self._get_pcomms(proc["pid"])):
                if self.misc_settings["dry_run"]:
                    logging.info(self._proc_dict_to_str(proc))
                else:
                    self._pids.append(proc["pid"])
        if self.misc_settings["dry_run"]:
            raise KeyboardInterrupt()
        self._send_signal(signal.SIGSTOP) 
Example 13
Project: ForceNap   Author: omikun   File: ForceNap.py    License: MIT License 5 votes vote down vote up
def suspend(prev_app):
    if name_of(prev_app) in DONT_SUSPEND_NAME:
        print(name_of(prev_app) + ' not suspended, in dont suspend list')
        return
    pids = get_pids(prev_app)
    logger.debug('Suspending %s (%s)', pids, name_of(prev_app))
    for pid in pids:
        SUSPENDED.add(pid)
        os.kill(int(pid), signal.SIGSTOP) 
Example 14
Project: ForceNap   Author: omikun   File: nap_my_app.py    License: MIT License 5 votes vote down vote up
def suspend(self):
        '''
        Suspend application and all processes associated with it
        '''
        if self.name in SUSPENSION_WHITELIST:
            return

        for pid in self.get_pids():
            if pid not in suspended_pids:
                logger.debug('Suspending %s (%s)', self.pid, self.name)
                suspended_pids.add(pid)
                os.kill(pid, signal.SIGSTOP)
        return 
Example 15
Project: vnpy_crypto   Author: birforce   File: __init__.py    License: MIT License 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if POSIX:
            self._send_signal(signal.SIGSTOP)
        else:  # pragma: no cover
            self._proc.suspend() 
Example 16
Project: nightmare   Author: joxeankoret   File: posix.py    License: GNU General Public License v2.0 5 votes vote down vote up
def handlePosixSignal(self, sig):
        """
        Handle a basic posix signal for this trace.  This was seperated from
        platformProcessEvent so extenders could skim events and still use this logic.
        """
        if sig == signal.SIGTRAP:

            # Traps on posix systems are a little complicated
            if self.stepping:
                #FIXME try out was single step thing for intel
                self.stepping = False
                self.fireNotifiers(vtrace.NOTIFY_STEP)

            elif self.checkWatchpoints():
                return

            elif self.checkBreakpoints():
                # It was either a known BP or a sendBreak()
                return

            elif self.execing:
                self.execing = False
                self.handleAttach()

            else:
                self._fireSignal(sig)

        elif sig == signal.SIGSTOP:
            #FIXME only on attaching..
            self.handleAttach()

        else:
            self._fireSignal(sig) 
Example 17
Project: psutil   Author: giampaolo   File: __init__.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if POSIX:
            self._send_signal(signal.SIGSTOP)
        else:  # pragma: no cover
            self._proc.suspend() 
Example 18
Project: teleport   Author: tp4a   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if POSIX:
            self._send_signal(signal.SIGSTOP)
        else:  # pragma: no cover
            self._proc.suspend() 
Example 19
Project: teleport   Author: tp4a   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if POSIX:
            self._send_signal(signal.SIGSTOP)
        else:  # pragma: no cover
            self._proc.suspend() 
Example 20
Project: teleport   Author: tp4a   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if POSIX:
            self._send_signal(signal.SIGSTOP)
        else:  # pragma: no cover
            self._proc.suspend() 
Example 21
Project: fast-autoaugment   Author: kakaobrain   File: safe_shell_exec.py    License: MIT License 5 votes vote down vote up
def terminate_executor_shell_and_children(pid):
    print('terminate_executor_shell_and_children+', pid)
    # If the shell already ends, no need to terminate its child.
    try:
        p = psutil.Process(pid)
    except psutil.NoSuchProcess:
        print('nosuchprocess')
        return

    # Terminate children gracefully.
    for child in p.children():
        try:
            child.terminate()
        except psutil.NoSuchProcess:
            pass

    # Wait for graceful termination.
    time.sleep(GRACEFUL_TERMINATION_TIME_S)

    # Send STOP to executor shell to stop progress.
    p.send_signal(signal.SIGSTOP)

    # Kill children recursively.
    for child in p.children(recursive=True):
        try:
            child.kill()
        except psutil.NoSuchProcess:
            pass

    # Kill shell itself.
    p.kill()
    print('terminate_executor_shell_and_children-', pid) 
Example 22
Project: pycopia   Author: kdart   File: proctools.py    License: Apache License 2.0 5 votes vote down vote up
def stop(self):
        os.kill(self.childpid, SIGSTOP) 
Example 23
Project: niryo_one_ros   Author: NiryoRobotics   File: sequence_code_executor.py    License: GNU General Public License v3.0 5 votes vote down vote up
def break_point(self):
        if self.process is None:
            return
        if self.is_executing_code():
            rospy.logwarn("Break point - pause sequence interruption")
            os.kill(self.process.pid, signal.SIGSTOP)
            self.is_paused = True 
Example 24
Project: ptracer   Author: pinterest   File: ptrace.py    License: Apache License 2.0 5 votes vote down vote up
def is_stop_signal(signum):
    return signum in (signal.SIGSTOP, signal.SIGTSTP,
                      signal.SIGTTIN, signal.SIGTTOU) 
Example 25
Project: gvm-tools   Author: greenbone   File: check-gmp.gmp.py    License: GNU General Public License v3.0 5 votes vote down vote up
def stop_process(self, pid):
        """Stop a running process

        Send a stop signal to the process with given pid

        Arguments:
            pid (int): Process Identification Number
        """
        os.kill(pid, signal.SIGSTOP) 
Example 26
Project: NoobSec-Toolkit   Author: krintoxi   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if _POSIX:
            self._send_signal(signal.SIGSTOP)
        else:
            self._proc.suspend() 
Example 27
Project: NoobSec-Toolkit   Author: krintoxi   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if _POSIX:
            self._send_signal(signal.SIGSTOP)
        else:
            self._proc.suspend() 
Example 28
Project: NoobSec-Toolkit   Author: krintoxi   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if _POSIX:
            self._send_signal(signal.SIGSTOP)
        else:
            self._proc.suspend() 
Example 29
Project: NoobSec-Toolkit   Author: krintoxi   File: __init__.py    License: GNU General Public License v2.0 5 votes vote down vote up
def suspend(self):
        """Suspend process execution with SIGSTOP pre-emptively checking
        whether PID has been reused.
        On Windows this has the effect ot suspending all process threads.
        """
        if _POSIX:
            self._send_signal(signal.SIGSTOP)
        else:
            self._proc.suspend() 
Example 30
Project: pychess   Author: pychess   File: SubProcess.py    License: GNU General Public License v3.0 5 votes vote down vote up
def pause(self):
        if sys.platform != "win32":
            try:
                self.proc.send_signal(signal.SIGSTOP)
            except ProcessLookupError:
                log.debug("SubProcess.pause(): ProcessLookupError", extra={"task": self.defname})