[CentOS] pup problem

Owen Beckley OwenB at foxriver.com
Wed Jun 2 18:31:56 UTC 2010


> From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On
> Behalf Of MHR
> Sent: Wednesday, June 02, 2010 12:21 PM
> To: CentOS mailing list
> Subject: Re: [CentOS] pup problem
> 
> On Wed, Jun 2, 2010 at 9:40 AM, Bowie Bailey <Bowie_Bailey at buc.com>
> wrote:
> > MHR wrote:
> >> #!/bin/bash
> >>
> >> # A shell script to kill that annoying runaway seamonkey that won't
> die
> >>
> >> case `basename $0` in
> >>         "seakill")      cmd=seamonkey;;
> >>         "foxkill")      cmd=firefox;;
> >>         *)                      echo "Unrecognized command."; exit
> 1;;
> >> esac
> >>
> >> kill -9 `ps -ef | grep $cmd | grep -v grep | tail -1 | awk '{print
> $2}'`
> >> ps -ef | grep $cmd | grep -v grep
> >>
> >> If it works, nothing is displayed.  If seamonkey/firefox is already
> >> gone, it give me kill's error for not finding the process (or for a
> >> missing process number because 'ps' couldn't find it, either).
> >>
> >
> > Isn't that command line a bit complex?  Why not use ps options to get
> > what you want rather than using grep, tail, and awk to pull the PID
> out
> > of the standard output?
> >
> >    ps -C $cmd -o pid= | xargs kill -9
> >    ps -fC $cmd
> >
> 
> It's an old script I rarely use.  Yours looks better - I'm taking it.
> :-)
> 
> Thanks
> 
> mhr

How about "pkill"?

pkill $cmd    # be nice
pkill -9 $cmd # be nasty
ps -fC $cmd   # see what still didn't die

--
Owen Beckley  -  owenb at foxriver.com





More information about the CentOS mailing list