Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from signal import SIGTERM
- from sys import exit
- from time import sleep
- from os import *
- def slow():
- fork()
- sleep(10)
- def fast():
- sleep(1)
- child_pids = []
- #for child_func in [fast, slow, slow, fast]:
- for child_func in [fast, fast]:
- pid = fork()
- if pid == 0:
- setsid()
- child_func()
- exit(0)
- else:
- print "spawned pgrp %d" % pid
- child_pids.append(pid)
- (pid, status) = waitpid(-1, 0)
- print "Reaped pid: %d, status: %d" % (pid, status)
- for child_pid in child_pids:
- try:
- print popen('ps -e -o pid,ppid,pgid,state,command | grep -i python').read()
- print "killing pg %d" % child_pid
- killpg(child_pid, SIGTERM)
- except OSError, e:
- print "Error killing %s: %s" %(child_pid, e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement