# Without the time.sleep(0.5), for me this is almost guaranteed to cause a 10 minute hang. # With the time.sleep(0.5), it will finish after about a minute, as expected. import os import time from signal import * def handler(s, c): os._exit(0) signal(SIGTERM, handler) for i in range(0, 100): pid = os.fork() if pid: # time.sleep(0.5) # this will make the child actually get killed os.kill(pid, SIGTERM) os.waitpid(pid, 0) else: time.sleep(600)