Created
August 20, 2013 19:29
-
-
Save winny-/6286050 to your computer and use it in GitHub Desktop.
Useful to see what signals your terminal emulator sends to its child "shell" process. It's poorly written and that's ok :).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import os | |
import psutil | |
def sighandler(signum, frame): | |
with open('/tmp/trapped', 'a') as f: | |
pid = os.getpid() | |
parent = psutil.Process(pid).parent | |
f.write('PID {3} captured signal {0}, parent {1} ({2}).\n'.format(signum,parent.name, parent.pid,pid)) | |
for i in [x for x in dir(signal) if x.startswith("SIG")]: | |
try: | |
signum = getattr(signal,i) | |
signal.signal(signum,sighandler) | |
except RuntimeError: | |
pass | |
except ValueError: | |
pass | |
while True: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment