LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-30-2004, 07:18 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
killing pids obtained from ps command


hi,

how can i kill the pids obtained using a ps and filterd out using grep.

eg--> ps -ef|grep "somethin" --> all pids obtained shud be killed

regards
SAN
 
Old 06-30-2004, 07:23 AM   #2
balanagireddy
Member
 
Registered: Sep 2003
Location: India
Distribution: redhat linux 9.0
Posts: 46

Rep: Reputation: 15
Hi,

U can kill the process by the following command.

kill -9 process-id (PID)

Here the process id (PID)
 
Old 06-30-2004, 08:13 AM   #3
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
its not that i want to kill the pids individually..
but i want to kill all the pids obtained from the above command with a compund command or a script
 
Old 06-30-2004, 08:18 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Try this:

kill -9 `pgrep app_you_want_to_kill`

pgrep will return a list of processes IDs for the name you specify.
 
Old 06-30-2004, 08:26 AM   #5
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Original Poster
Rep: Reputation: 15
but there nothin like pgrep in HP-UX and so it wont work out.
 
Old 06-30-2004, 11:35 AM   #6
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
I'm guessing the most portable way to do this is like

Code:
ps -awwx |grep "$stuff_to_grep_for"|awk '{print $1}'|xargs kill
Check if ww does for you what it does for me, that is cause the output not to be truncated at 80 columns.
 
Old 06-30-2004, 11:46 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
On linux there's "killall" which takes executable names itself. E.g.g "killall xterm" kills all xterms that I'm allowed to kill. Does it exist on HP-UX? If not, stick with aluser's solution.
 
Old 06-30-2004, 12:02 PM   #8
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
There is a killall for HPUX, but do not use it. It is really meant for something slightly different - it doesn't take an argument like that.
 
Old 06-30-2004, 12:12 PM   #9
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
haha is that the killall that *kill*s *all* processes?
 
Old 06-30-2004, 12:13 PM   #10
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
ps -C name_of_program -o pid= | xargs kill
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
killing x11 from the command line Kaamoss Slackware 9 10-16-2005 06:57 AM
can't use/locate some packages obtained by apt-get Andramalech Debian 4 05-21-2005 07:03 PM
Parent PIDs Sinope Linux - Newbie 6 10-05-2004 11:46 PM
C++ and PIDs dbcoder Programming 1 07-15-2004 08:58 PM
killing pids i_is_cat Linux - Newbie 6 05-01-2003 11:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration