Created
December 18, 2013 02:23
-
-
Save non117/8016354 to your computer and use it in GitHub Desktop.
親が死んだら自殺する子.py
This file contains 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
import multiprocessing | |
import os | |
import time | |
def is_alive(pid): | |
try: | |
os.kill(pid, 0) | |
except OSError: | |
return False | |
else: | |
return True | |
def worker(parent_pid): | |
waiting = True | |
while waiting: | |
if is_alive(parent_pid): | |
pass | |
else: | |
waiting = False | |
if __name__ == '__main__': | |
p = multiprocessing.Process(target=worker, args=(os.getpid(),)) | |
p.daemon = True | |
p.start() | |
time.sleep(10) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment