Find a process by name and automatically kill it

PID=$(ps -ef | grep processName | grep -v grep | awk '{print $2'}); kill -9 $PID

0
2014-11-11 05:12:19

2 Alternatives + Submit Alt

What Others Think

pkill -f process_name
doomedraven · 201 weeks and 6 days ago
OK, even if pkill/pgrep/killall didn't exist... Your command is lacking a 'fu'-ness to it. ... | grep processName | grep -v grep | ... command 2997 "Find the process you are looking for minus the grepped one" http://www.commandlinefu.com/commands/view/2997 ... | grep processNam[e] | awk ... Why search with grep, when awk can do it: ... | awk '/processNam[e]{print $2} Next. Why use a variable when the subshell will do: kill -9 $( [find process id] ) Altogether: kill -9 $(ps -ef | awk '/processNam[e]/{print $2}') Three processes instread of five. Fewer characters to type. Much more 'fu'.
flatcap · 201 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: