Killing the entire process from the command line

I would like to kill all firefox processes from the command line.

For instance:

MacPro:huangr$ ps -x | grep 'firefox' 4147 ttys000 0:00.00 (firefox-bin) 4177 ttys000 0:00.00 (firefox-bin) 4234 ttys000 0:00.00 (firefox-bin) 4273 ttys000 0:00.00 (firefox-bin) 4282 ttys000 0:00.00 (firefox-bin) 4285 ttys000 0:00.00 (firefox-bin) 4298 ttys000 0:00.00 (firefox-bin) 4301 ttys000 0:00.00 (firefox-bin) 4304 ttys000 0:00.00 (firefox-bin) 4311 ttys000 0:00.00 (firefox-bin) 4317 ttys000 0:00.00 (firefox-bin) 4320 ttys000 0:00.00 (firefox-bin) 4338 ttys000 0:00.00 (firefox-bin) 4342 ttys000 0:00.00 (firefox-bin) 4377 ttys000 0:03.85 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 4394 ttys000 0:05.54 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 4471 ttys000 0:06.08 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 4581 ttys002 0:04.92 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 4607 ttys002 0:04.33 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 4626 ttys002 0:05.04 /Applications/Firefox.app/Contents/MacOS/firefox-bin -no-remote -foreground 

I would like to kill all of them with one shot, in any simple way to do this? Thanks.

+4
source share
5 answers
 kill -9 $(ps -x | grep 'firefox' | awk '{print $1}') 

Gotta do it

+9
source

This works great.

 ps -ef | grep '[f]irefox' | awk '{print $1}' | xargs kill -9 ; 

or

 ps -ef | awk '/[f]irefox/ {print $1}' | xargs kill -9 ; 
+2
source

Side Note -

kill -9 is redundant (not intended for pun intended) because it prevents the kill process from starting (for example, calls to atexit (), like the difference between exiting and _exit). This may or may not be a problem with firefox, but in general, consider trying to kill -9 only after a failed kill.

+1
source

killall firefox-bin

or

killall -9 firefox-bin

if necessary

0
source

That should do it -

 kill `awk '$4~/firefox/{print $1}' <(ps -x)` 

Or in a general note, add this function to your script run -

 killp() { awk -v pname="$1" '$4~/pname/{print $1}' <(ps -e) | xargs kill } 

Test:

 [jaypal:~/Temp] sleep 100& [1] 52530 [jaypal:~/Temp] sleep 100& [2] 52531 [jaypal:~/Temp] killp sleep [1]- Terminated: 15 sleep 100 [2]+ Terminated: 15 sleep 100 
0
source

Source: https://habr.com/ru/post/1387445/


All Articles