Proper way to kill child processes

P at draigBrady.com P at draigBrady.com
Wed Jun 16 15:23:05 CEST 2004


Bob Swerdlow wrote:
> My application starts up a number of processes for various purposes using:
>     self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py")
> and then shuts them down when appropriate with
>     os.kill(self.popen.pid, signal.SIGTERM)
> Everything works fine on MacOSX.  However, I'm doing a port to Solaris (so I
> can run it on my web site) and find that the child processes are not
> stopping!  Solaris is creating TWO new processes: one for the SHELL and then
> another started by the shell to run my Python script.  The os.kill() is
> killing the shell process, not the one running my Python code.
> 
> Actually, I really want to kill both of these processes, but I only have the
> pid for the shell process.  I cannot kill the whole process group because
> that kills the main process, too (I tried it).

Try to get the popen2.Popen3() implementation to create it's own
process group. You can do this by adding an os.setpgrp() call
or maybe you can change the "sh -c" -> "sh -mc"

Pádraig.




More information about the Python-list mailing list