The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: kill
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 05-14-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,064
Which field to match on really depends on which platform you are on and which ps options you are using -- these vary rather wildly.

As such, good advice -- especially if the command name is short an cryptic, you might get accidental matches. As always, look before you dive.

The use of [a]bc is a trick to avoid having the script find and kill itself in the listing; unlike "abc", "[a]bc" does not match itself, so it avoids this suicide syndrome. There are other ways to work around that, of course. Here's one attempt.

Code:
ps -ef | awk '$9 == "a" "bc" { print $2 }' | xargs kill
Unlike a regular expression, which matches anywhere within a command name, this one requires the entirety of field 9 to be exactly equivalent to the concatenated string "abc". That may or may not be what you need, again depending on how the command was invoked and on how your version of ps shows the information.
Reply With Quote