Run python function when parent dies

import signal, ctypes, os

# @formatter:off - set sigterm handler for when parent dies
if os.path.exists("/lib/aarch64-linux-gnu/libc.so.6"): libc = ctypes.CDLL("/lib/aarch64-linux-gnu/libc.so.6")
else: libc = ctypes.CDLL("/lib/x86_64-linux-gnu/libc.so.6")
PR_SET_PDEATHSIG = 1; TERM = 15; libc.prctl(PR_SET_PDEATHSIG, TERM)
# @formatter:on

def term(signum, frame):
    pass
signal.signal(signal.SIGTERM, term)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *