Skip to content

Instantly share code, notes, and snippets.

@non117

non117/suicide.py

Created Dec 18, 2013
Embed
What would you like to do?
親が死んだら自殺する子.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