Skip to content

Instantly share code, notes, and snippets.

@winny-
Created August 20, 2013 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winny-/6286050 to your computer and use it in GitHub Desktop.
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 :).
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