Proper way to kill child processes

Bob Swerdlow rswerdlow at transpose.com
Wed Jun 16 09:29:24 EDT 2004


Thanks for this tip - it worked.

I never would have thought that the format of the parameters would have such
a side effect, though in hindsight I guess it makes sense that the shell is
needed to parse the command if it is passed as a single string.  It's not
clear why that did not cause an additional process to created on MacOSX, but
this solution worked.

I appreciate your help.
- Bob

----- Original Message ----- 
From: <mrjean1 at comcast.net>
To: <rswerdlow at transpose.com>
Sent: Tuesday, June 15, 2004 5:50 PM
Subject: Re: Proper way to kill child processes


>
> Try a different format for the cmd:
>
>  self.popen = popen2.Popen3(["/usr/local/bin/python", "-O",
> "myscript.py"])
>
> i.e. pass the cmd as a list of the individual arguments.  That avoids
> invoking the sh.  See <your_python_install>/Lib/popen2.py for more
> details.
>
> /Jean Brouwers
>  ProphICy Semiconductor, Inc.
>
>
>
> In article <mailman.10.1087331713.21521.python-list at python.org>, Bob
> Swerdlow <rswerdlow at transpose.com> 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).
> >
> > So, what is the best way to kill both the shell process (whose pid is
> > available from the Popen3 object) and its child process that is running
my
> > Python script?  It looks like the python script process id is always one
> > greater than the shell process id of the shell process,  but I'm sure I
> > cannot rely on that.
> >
> > Thanks,
> >
> > Bob Swerdlow
> > COO
> > Transpose
> > rswerdlow at transpose.com
> > 207-781-8284
> > http://www.transpose.com
> >
> > ----------------------------------
> > Fight Spam!
> > Add this link to your signature (as I did): http://wecanstopspam.org
> > Click through to find out more.
> > ----------------------------------
>
>






More information about the Python-list mailing list