kill childs

Christian Schmidt Christian.Schmidt at
Thu Feb 28 09:22:36 EST 2002

> He's aiming at the process group, which is a good idea.  os.kill(-1, sig)
> will work, though of course the signal will be delivered to the calling
> process as well.  It might be a good idea to set a flag indicating that
> the process group kill has already happened, to avoid an infinite loop.
I tried this one... and it worked. Here's my script.
import signal, os, sys

term_childs_first = 1 # static variable for signal handler

def term_childs (signal, frame):
    global term_childs_first
    if term_childs_first: # first kill of parent process
        term_childs_first = 0
        os.kill (-1, signal) # process group kill
    else: # second kill, because of process group kill
        sys.exit (signal) # exit with signal
# end term_childs

signal.signal (signal.SIGTERM, term_childs) # install signal handler for
print os.getpid()
os.system("ls -laR / > NUL") # long running commandline
print "long running command completed."

More information about the Python-list mailing list