Re: [ILUG] kill process by name

From: David Neary (dneary at domain wanadoo.fr)
Date: Tue 16 Jul 2002 - 13:03:55 IST


Kenn Humborg wrote:
> > ps -ao pid,args | grep 'command' | awk '{print $1}' | xargs kill
>
> There is nothing to prevent the grep command itself being killed
> before it finishes.

Good point. That grep could be changed to
grep '[c]ommand'
or something similar that won't match itself.

> but in a script you need to be much more careful. Some of the
> processes you want to kill just might have 'grep' in their
> command name or arg list.

Yes, hmm... I can't see any nice way to get around this with
shell hackery on $1. If the script is called with (say)
kill_foo '[^.]\<java\>'
to avoid killing javac processes, and java_vms (or whatever), and
editors editting .java files, then the grep wouldn't work on
itself, but to prevent it from working on itself in general, you
need to do some tomfoolery to restrict the class of regexps it
can take. Hmmm...

Good point.

Cheers,
Dave.

-- 
       David Neary,
    Marseille, France
  E-Mail: bolsh at domain gimp.org


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:55 GMT