Last active
August 29, 2015 14:06
-
-
Save nirs/e4be478da3f5f55116c1 to your computer and use it in GitHub Desktop.
Example of signal mask inheritance using python-signalfd package
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
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