Skip to content

Instantly share code, notes, and snippets.

@nirs
Last active August 29, 2015 14:06

Revisions

  1. nirs renamed this gist Sep 6, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions signalfd.sigprocmask example → sigprocmask.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    from __future__ import print_function
    import os
    from __future__ import print_function
    import signal
    import signalfd
    import sys
  2. nirs created this gist Sep 6, 2014.
    41 changes: 41 additions & 0 deletions signalfd.sigprocmask example
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    from __future__ import print_function
    import os
    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()