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 gimp.org
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!