how to kill a python process?

Jorgen Grahn grahn+nntp at snipabacken.dyndns.org
Sun Feb 5 12:48:18 EST 2006


On 5 Feb 2006 09:10:04 -0800, MackS <mackstevenson at hotmail.com> wrote:
> Hello!
>
> This question does not concern programming in python, but how to manage
> python processes. Is there a way to "name" a python process? At least
> on Linux, if I have two python programs running, they both run under
> the name "python"
...
> Is there a way to make them run under their own names, e.g., to make it
> easier to kill them by name using killall?

Funny, I had to experiment a bit to see how it worked. This is surely a FAQ,
because it's important. IMHO, the interpreter for a Unix program should be
invisible, so that the program behaves like as a first-class process in
every way.

  $ python foo1.py

This one gets called 'python', as expected.

  $ head -1 foo2.py
  #!/usr/bin/env python
  $ ./foo2.py

This one gets called 'python', too. I've been using this version because I
read somewhere it was the recommended idiom -- but I will stop doing it now
that I know it mangles the process name.

  $ head -1 foo3.py
  #!/usr/bin/python
  $ ./foo3.py

This is the traditional shebang form used for shell and Perl scripts,
and it names the process 'foo3.py' so you can killall(1) it nicely.

> Or am I stuck with
> registering the pid of each python process I create and then refer to
> that list whenever I need to selectively stop one of them?

If a program starts another one and needs to kill it, it /should/ remember
its pid. You don't want programs which cannot live together on one machine
without killing each other's children.

But as I wrote above, you /do/ want to have meaningful information in
top(1), ps(1) and so on.  Having half a dozen processes named python (or
java, or whatever) and wanting to kill one specific is not my idea of fun
...

/Jorgen

-- 
  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.dyndns.org>  R'lyeh wgah'nagl fhtagn!



More information about the Python-list mailing list