Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 May 2000 17:18:32 +0200
From:      Gerhard Sittig <Gerhard.Sittig@gmx.net>
To:        stable@FreeBSD.ORG
Subject:   Re: killall question
Message-ID:  <20000527171832.F2305@speedy.gsinet>
In-Reply-To: <200005271258.IAA29766@thehousleys.net>; from housley@thehousleys.net on Sat, May 27, 2000 at 12:58:25PM -0000
References:  <200005271258.IAA29766@thehousleys.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, May 27, 2000 at 12:58 -0000, housley@thehousleys.net wrote:
> Randall Hopper <aa8vb@nc.rr.com> said: 
> 
> > I have a script I run named "newroot".  I want to kill it
> > with killall.
> >         
> >     > ps -ax | grep newroot
> >      842     1 rhh    /bin/sh /home/rhh/bin/newroot 360

As you can see, the process name is '/bin/sh' and the newroot
script is just a parameter upon invocation.

> You will have to do something like
> 
> kill `ps -ax | grep newroot | sed -e '^[0-9]*'`

It's the usual habit of either -v grepping the grep command
itself or writing the search pattern in a way that it doesn't
match on itself.  Otherwise you could hit two commands:  The
grepped and grep, depending on the machine's load and the
"freshness" of the ps output (sorry, I lack a better word).  This
might be not so big an issue, but I wouldn't want to search for
such an error if you do more than just a kill and when it
suddenly matters if you accidently kill your grep, too.

Make it read something like

  ps -ax | grep 'new[r]oot' | ...
  ps -ax | grep newroot | grep -v grep | ...

and cut(1) could be your friend for getting the PID (do I miss
something when I feel the above sed example is missing a subst
command?  I would expect at least something like

  ... | sed 's/ .*$//'
  ... | sed 's/^\([0-9]*\)/\1/'

).


BTW These are situations where I feel PID files appropriate.
"echo $! > $FILE" upon service's start (when using a bourne
shell) and "kill -TERM $( cat $FILE )" when shutting down.  This
way you can test for existence of this file at will or deliver
any signal you want.  Or go ahead and look out for daemontools.

And once you start wrapping your service with an up and down
script there's not long a way towards SysV boot scripts.  I
really wished FreeBSD had them, too.  Especially when you
temporarily want to stop and restart a service or if the service
is of temporary nature only (as I had it lately with the NFS
mounted installworld), I feel SysV scripts to be a real big gain.
Instead I had to grep and read the rc scripts to start every
detail by hand and kill them afterwards.  BSD rc scripts are more
appropriate for editing rc.conf and rebooting if you're not 100%
sure of what you have to do in detail (and even experienced
admins fail to always get it right).

If there are serious thoughts about incorporating SysV style boot
scripts into FreeBSD I'm willing to help.  But if this topic is
only good for starting religious (and thus inproductive) threads
I don't want to get an answer on this. :)  Not that I was afraid
of discussing things in public -- it's just that I don't want to
waste resources.  Otherwise I already had asked why ee is the
default editor in the installation procedure. :>


virtually yours   82D1 9B9C 01DC 4FB4 D7B4  61BE 3F49 4F77 72DE DA76
Gerhard Sittig   true | mail -s "get gpg key" Gerhard.Sittig@gmx.net
-- 
     If you don't understand or are scared by any of the above
             ask your parents or an adult to help you.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000527171832.F2305>