Capturing SIGSTOP

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Nov 24 01:36:53 EST 2011


On Thu, 24 Nov 2011 15:22:23 +1100, Chris Angelico wrote:

> On Thu, Nov 24, 2011 at 2:29 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> Is there a way to catch SIGSTOP?
> 
> In the strictest sense, no; SIGSTOP can't be caught. However, some
> systems have SIGTSTP which is sent when you hit Ctrl-Z, which would be
> what you're looking for.

That's exactly what I'm looking for, thanks.

After catching the interrupt and doing whatever I need to do, I want to 
allow the process to be stopped as normal. Is this the right way?

import signal, os

def handler(signalnum, stackframe):
    print "Received signal %d" % signalnum
    os.kill(os.getpid(), signal.SIGSTOP)  # Hit myself with a brick.

signal.signal(signal.SIGTSTP, handler)


It seems to work for me (on Linux), but is it the right way?



-- 
Steven



More information about the Python-list mailing list