The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Diff b/n kill and kill -9 ammu UNIX for Advanced & Expert Users 2 07-18-2007 06:29 PM
kill(0,-9) don't kill the process umen High Level Programming 9 06-19-2007 07:09 AM
not able to kill find with kill -9 Amardeep UNIX for Dummies Questions & Answers 5 01-04-2007 05:49 PM
KILL PID, intern should kill another PID. rkrgarlapati Shell Programming and Scripting 4 10-17-2006 08:47 AM
When kill doesnt work, how to kill a process ? VijayHegde UNIX for Advanced & Expert Users 3 05-12-2006 05:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-14-2008
tukuna82 tukuna82 is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 8
kill

Lets a process name abc.
how can i kill it in one line command?
  #2 (permalink)  
Old 05-14-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Depending on the OS, you may be able to use pkill abc.

Otherwise, try ps -ef | awk '/[a]bc/ { print $2 }' | xargs kill.
  #3 (permalink)  
Old 05-14-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi,

there may be multiple occurences of string abc in the output of
ps -ef.

In that case all those processes will be killed i think.

In awk, matching shoule be done 9th field.

Thanks
Penchal
  #4 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.
  #5 (permalink)  
Old 05-14-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi era,

Cant i use .

ps -ef | awk '$9 == "abc" { print $2 }' | xargs kill

instead of

ps -ef | awk '$9 == "a" "bc" { print $2 }' | xargs kill

Thanks
Penchal
  #6 (permalink)  
Old 05-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Yes, come to think of it, the suicide issue only applies when the script's arguments might match.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0