Kill Linux Processes with pkill

One of the best features in Linux is the way you can control processes from the command line, so if you have an application that locks up your GUI, you can always SSH over from another machine and just kill the offending process.

The problem is that if you are killing the same process repeatedly, it’s very tedious to have to figure out the process ID every single time so that you can kill it… so here’s the easier way to do it.

The Old Way

The classic way of killing processes meant you’d first need to use the ps command piped through grep to find the process you are trying to kill:

$ ps -ef | grep swiftfox
geek 7206 22694 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/swiftfox
geek 7209 7206 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/ /opt/swiftfox/swiftfox-bin
geek 7213 7209 0 Dec04 ? 00:04:29 /opt/swiftfox/swiftfox-bin
geek 14863 14224 0 18:19 pts/4 00:00:00 grep swiftfox

Then to kill the process, you’d have to use the kill command:

$ kill 7206
The New Way

Instead of going through all of that, you can simply use the pkill command if you already know the process name or part of it.

$ pkill swiftfox
It’s as simple as that. You should note that pkill will kill all processes matching the search text, in this case swiftfox

If you want to see what process names are matched before using the pkill command, you can use the pgrep command. Passing the -l switch tells pgrep to show the process name as well.

$ pgrep -l swiftfox
7206 swiftfox
7213 swiftfox-bin

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl


GST Training said...

Hey keep posting such good and meaningful articles.

americanairheatingco said...

Nice tips....
air conditioning replacement

Tangki Fiber said...

Hello, Why we should kill linux processes?

Tangki Panel

hide online said...

It’s really awesome. I love it.very interesting and meaningful post. I got some very important views in your post which are very good and applicable for me. I just wish that I’ll see your another post very soon. I am waiting for that.

kajal agarwal hot said...

Vest Nice blog for learning new things,thanks for such beautiful blog.
below some new idea plz check once.

midn said...

replica moncler jackets, combining elegant style and cutting-edge technology, a variety of styles of replica moncler shoes, the pointer walks between your exclusive taste style.

invincible01 said...

Amazing Article, Really useful information to all So, I hope you will share more information to be check and share here.

inplant training
inplant training chennai
inplant training in chennai
inplant training at chennai
inplant training
inplant training chennai
inplant training in chennai
inplant training at chennai
inplant training
Inplant Training for cse

Post a Comment

Popular Posts