Created
July 15, 2014 21:40
-
-
Save otherwiseguy/6f069f7ba2203864c666 to your computer and use it in GitHub Desktop.
An example how in python on linux you can ensure that a signal gets passed to a child on its parent's death
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
#!/usr/bin/env python | |
from prctl import prctl, PDEATHSIG # https://pypi.python.org/pypi/prctl/1.0.1 | |
import signal as sig | |
import subprocess | |
p = subprocess.Popen(['yes'], preexec_fn=lambda: prctl(PDEATHSIG, sig.SIGTERM)) | |
p.communicate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running deathsig will start 'yes' which just echoes 'y' forever. Without the preexec_fn, killing deathsig results in yes being reparented to init and continuing to run indefinitely. With it, SIGTERM is sent to the 'yes' child process on parent death, allowing it to terminate.