1821216 Members
3098 Online
109632 Solutions
New Discussion юеВ

Kill All command

 
SOLVED
Go to solution
Kyle D. Harris
Regular Advisor

Kill All command

What do you do if say you have 100 processes and want maybe 90 killed. How do you kill 90 but keep 10? Is there a quick easy way? Thanks
8 REPLIES 8
Mark Grant
Honored Contributor

Re: Kill All command

No there isn't.

You could, of course, kill all 100 with the "killall" command and then start 10 up again.
Never preceed any demonstration with anything more predictive than "watch this"
Olivier Drouin
Trusted Contributor
Solution

Re: Kill All command

kill -9 `ps -ef | grep process | awk '{print $2}' | tail -90`

... or something like that. If your program is setup as a father/child then you will have to add some code not the kill the father.
Thierry Poels_1
Honored Contributor

Re: Kill All command

Hi,

how about something like:

ps -ef |grep telnet | grep -v grep | awk '{print $2}' | tail +11 | xargs kill

(just hoping "tail +n" is supported under Linux ;)
good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Mark Grant
Honored Contributor

Re: Kill All command

Shows how much I know :)

However, I would point out that selecting processes by "grep" is rather dangerous as you can kill thinks you didn't expect unless extreme care is taken.

Also, please don't kill -9 unless your really have to. -15 or just plain "kill" allows the process to exit gracefully, closing files and doing any clean up it requires whereas -9 kills it dead. Many applications fail when you restart them if this happens.
Never preceed any demonstration with anything more predictive than "watch this"
Jerome Henry
Honored Contributor

Re: Kill All command

And (no criticism here of course) yu don't really select which you kill and which you save, except that yu keep 10 of them...

J
You can lean only on what resists you...
Kyle D. Harris
Regular Advisor

Re: Kill All command

Lol Mark....

Jim Butler
Valued Contributor

Re: Kill All command

kill `ps -e | grep procname | awk '{print $1}' `

- my favorite way -

Good Luck
Man The Bilge Pumps!
Martin P.J. Zinser
Honored Contributor

Re: Kill All command

Somebody mentioned father/child realations and to take care not to kill the father. That can also work the other way round. In case these are all sub processes of a single parent process it might be enough to just kill that parent process to make them all go away...