From owner-freebsd-stable Sat May 27 12:17:25 2000 Delivered-To: freebsd-stable@freebsd.org Received: from mail.gmx.net (pop.gmx.net [194.221.183.20]) by hub.freebsd.org (Postfix) with SMTP id BAC2437B5AC for ; Sat, 27 May 2000 12:17:11 -0700 (PDT) (envelope-from Gerhard.Sittig@gmx.net) Received: (qmail 7389 invoked by uid 0); 27 May 2000 19:17:10 -0000 Received: from p3ee0b3fa.dip.t-dialin.net (HELO speedy.gsinet) (62.224.179.250) by mail01.rzmi.gmx.net with SMTP; 27 May 2000 19:17:10 -0000 Received: (from sittig@localhost) by speedy.gsinet (8.8.8/8.8.8) id RAA27241 for stable@FreeBSD.ORG; Sat, 27 May 2000 17:18:32 +0200 Date: Sat, 27 May 2000 17:18:32 +0200 From: Gerhard Sittig To: stable@FreeBSD.ORG Subject: Re: killall question Message-ID: <20000527171832.F2305@speedy.gsinet> Mail-Followup-To: stable@FreeBSD.ORG References: <200005271258.IAA29766@thehousleys.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <200005271258.IAA29766@thehousleys.net>; from housley@thehousleys.net on Sat, May 27, 2000 at 12:58:25PM -0000 Organization: System Defenestrators Inc. Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sat, May 27, 2000 at 12:58 -0000, housley@thehousleys.net wrote: > Randall Hopper 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