Skip to content

Instantly share code, notes, and snippets.

@non117
Created December 18, 2013 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save non117/8016354 to your computer and use it in GitHub Desktop.
Save non117/8016354 to your computer and use it in GitHub Desktop.
親が死んだら自殺する子.py
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