In some cases killing a single tab/process doesn't do it and I need to close Chrome entirely. Since Chrome has multiple processes, how can I close all of them at once?

I know that...

pgrep chrome returns all the pids. What is a trick that would allow me to close all of them by feeding them to another command or merging them to a CSV file or something?

link|improve this question

62% accept rate
Since there are at least three answers here that needlessly do kill -9, here are three reference discussing the reasons that should be your last choice: When should I use kill -9, kill -9 and Useless use of kill -9. – Dennis Williamson Apr 14 '10 at 20:57
feedback

migrated from stackoverflow.com Apr 14 '10 at 20:02

This question came from our site for professional and enthusiast programmers.

6 Answers

Try using pkill(1).

pkill chrome

link|improve this answer
just be aware that pkill might not be on all systems, but if you have pgrep, more than likely pkill exists as well. – kSiR Apr 14 '10 at 19:36
feedback
ps aux | grep chrome | awk ' { print $2 } ' | xargs kill -9

or

pgrep chrome | xargs kill -9

or

ps aux | awk '/chrome/ { print $2 } ' | xargs kill -9

The latter is more "elegant" as it will not pick up the actual pid for "grep chrome" inside of its ps listing

:-)

link|improve this answer
Is there any reason to use ps ... | instead of pgrep, even supposing you don't want to use pkill? – Jefromi Apr 14 '10 at 19:36
1  
It's also always polite to start with SIGTERM before escalating to SIGKILL. – Jefromi Apr 14 '10 at 19:39
not really, only reason i threw the ps option out there is due to alot of my systems are bare bones meaning we dont have things like pkill pgrep – kSiR Apr 14 '10 at 19:39
I agree, but one just asked to kill :-O s/-9/-1/g – kSiR Apr 14 '10 at 19:39
feedback

You should really just use pkill as jschmier suggests, but if you insist on pgrep, just use command substitution:

kill $(pgrep chrome)
link|improve this answer
would'nt kill pgrep chrome`` also work ;) – kSiR Apr 14 '10 at 19:53
@kSiR: [a month late] yes, but $(...) is a great habit to get into so you can nest when you need to, and flip between matching delimiters in your editor. – Jefromi May 12 '10 at 18:27
feedback

Some systems may also have useful programs such as killall and pidof (which is actually provided by the System V killall5):

killall chrome
kill -9 `pidof chrome`

Both of these should accomplish what you are asking.

link|improve this answer
You shouldn't use -9 except as a last resort. Do kill PID first. – Dennis Williamson Apr 14 '10 at 20:52
feedback

You can also try something like this:

ps -C chrome |cut -f 1 -d' ' | xargs kill
link|improve this answer
You shouldn't use -9 except as a last resort. Do kill PID first. – Dennis Williamson Apr 14 '10 at 20:53
good point. I updated my answer. – Nathan Fellman Apr 15 '10 at 7:08
feedback

The easiest command is this one:

sudo killall chrome

This will, with administrative permissions, kill all processes that contain chrome in their name.

See man killall for more information...

link|improve this answer
2  
Could you add a bit of explanation about how your answer works? – nhinkle Nov 1 '11 at 4:43
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.