Subject: Re: How do I "kill" a process from a script when the PID changes.
Subject: Re: How do I "kill" a process from a script when the PID changes.
Subject: Dangerous use of "kill -9" (was Re: How do I "kill" a process
from a script when the PID changes.)
Subject: Re: How do I "kill" a process from a script when the PID changes.
From: Barry Margolin <barmar@bbnplanet.com>
Newsgroups: comp.unix.questions
Subject: Re: How do I "kill" a process from a script when the PID changes.
Originator: barmar@bbnplanet.com (Barry Margolin)
Lines: 19
Distribution: world
Date: Fri, 09 Apr 1999 20:43:35 GMT
In article <7elka0$7vo$1@blackice.winternet.com>,
>
>I solved this once, nice and simple, pipe it to |head -1:
>
>kill -9 `ps auxw |grep "process" | awk '{print $2}'|head -1`
You don't have any control over the order that ps displays. What happens
if the grep line is displayed first by ps?
Why is this better than the other solutions that were already posted (pipe
to "grep -v grep", or change the pattern to have brackets around one of the
characters)?
--
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
--
From: ken@halcyon.com (Ken Pizzini)
Newsgroups: comp.unix.questions
Subject: Re: How do I "kill" a process from a script when the PID changes.
Date: 10 Apr 1999 02:34:27 GMT
Lines: 25
Reply-To: ken@halcyon.com
User-Agent: slrn/0.9.5.3 (UNIX)
>I solved this once, nice and simple, pipe it to |head -1:
>
>kill -9 `ps auxw |grep "process" | awk '{print $2}'|head -1`
This is getting out of hand...
1. As Randall pointed out in his message, "kill -9" should only
be used as a last resort; use a plain "kill" for ordinary use:
kill `ps auxw | grep "process" | awk '{print $2}' | head -1`
2. The "grep | awk" fragment is a Useless Use Of Grep:
kill `ps auxw | awk '/process/ {print $2}' | head -1`
3. The "awk | head" fragment is a Useless Use Of Head:
kill `ps auxw | awk '/process/ {print $2; exit}'`
4. There is no guarantee that that will kill the desired
process rather than the awk command itself; it may work
most of the time for you, but it will sometimes fail.
Better to just avoid having the awk process match in
the first place by tweaking the RE being matched:
kill `ps auxw | awk '/[p]rocess/ {print $2}'`
5. You might want to check to see if your system has a
utility such as "skill" installed, which handles this
in an even cleaner manner:
skill -c process
--Ken Pizzini
--
Newsgroups: comp.unix.questions
Subject: Dangerous use of "kill -9" (was Re: How do I "kill" a process from a script when the PID changes.)
From: merlyn@stonehenge.com (Randal L. Schwartz)
Lines: 33
Date: 08 Apr 1999 12:37:42 -0700
>>>>> "aphid" == aphid <aphid@my-dejanews.com> writes:
aphid> kill -9 `ps auxw |grep "process" | awk '{print $2}'`
No no no. Don't use kill -9.
It doesn't give the process a chance to cleanly:
1) shut down socket connections
2) clean up temp files
3) inform its children that it is going away
4) reset its terminal characteristics
and so on and so on and so on.
Generally, send 15, and wait a second or two, and if that doesn't
work, send 2, and if that doesn't work, send 1. If that doesn't,
REMOVE THE BINARY because the program is badly behaved!
Don't use kill -9. Don't bring out the combine harvester just to tidy
up the flower pot.
Just another Useless Use of Usenet,
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
--
From: Alain Guisolan <bguisa@abs.ascom.ch>
Newsgroups: comp.unix.questions
Subject: Re: How do I "kill" a process from a script when the PID changes.
Date: Wed, 07 Apr 1999 10:05:38 +0200
Lines: 29
Mime-Version: 1.0
Hi,
I'd capture the process id when starting it by using $! i.e.
yourScript &
process=$!
...
kill -9 $process
--
Al
aphid@my-dejanews.com wrote:
>
> I need to close a process and delete some files associated with it every day.
> I am using cron to do this.
>
> To close the process, I can do the following:
>
> kill -9 `ps auxw |grep "process" | awk '{print $2}'`
>
> The problem is:
> 1) It doesn't work because ps auxw | grep process gives:
> User PID ... grep process
> User PID ... process
> Since these are on two separate lines, kill does not work.
> 2) Isn't there a better way to do this.
>
> Shell: csh
--
|
Hosted by: |
|
©copyright 1995-2002 sysinfo.com