Skip to content

Instantly share code, notes, and snippets.

@nirs
Last active August 29, 2015 14:06
Show Gist options
  • Save nirs/e4be478da3f5f55116c1 to your computer and use it in GitHub Desktop.
Save nirs/e4be478da3f5f55116c1 to your computer and use it in GitHub Desktop.
Example of signal mask inheritance using python-signalfd package
from __future__ import print_function
import signal
import signalfd
import sys
import threading
def report():
mask = signalfd.sigprocmask(signalfd.SIG_BLOCK, [])
print('- pid: %s thread: %s mask: %s' % (
os.getpid(), threading.current_thread(), mask))
print('parent starting pid: %s' % os.getpid())
signalfd.sigprocmask(signalfd.SIG_BLOCK, [signal.SIGTERM, signal.SIGINT, signal.SIGHUP])
report()
print('starting a thread in parent...')
threading.Thread(target=report).start()
pid = os.fork()
if pid:
os.waitpid(pid, 0)
else:
print('child starting pid: %s...' % os.getpid())
report()
print('starting a thread in child...')
threading.Thread(target=report).start()
pid = os.fork()
if pid:
os.waitpid(pid, 0)
else:
print('subchild starting pid: %s...' % os.getpid())
report()
print('starting a thread in sub child...')
threading.Thread(target=report).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment