User Tools

Site Tools


killaprocess

Kill Linux Processes Easier 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&rsquo;d first need to use the ps command piped through grep to find the process you are trying to kill: <blockquote>

$ ps -ef | grep swiftfox<br />geek 7206 22694 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/swiftfox<br />geek 7209 7206 0 Dec04 ? 00:00:00 /bin/sh /opt/swiftfox/run-mozilla.sh /opt/swiftfox/swiftfox-bin<br />geek 7213 7209 0 Dec04 ? 00:04:29 /opt/swiftfox/swiftfox-bin<br />geek -4863 14224 0 18:19 pts/4 00:00:00 grep swiftfox </blockquote>

Then to kill the process, you&rsquo;d have to use the kill command: <blockquote>

$ kill 7206 </blockquote>

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. <blockquote>

$ pkill swiftfox </blockquote>

It&rsquo;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. <blockquote> $ pgrep -l swiftfox<br />7206 swiftfox<br />7213 swiftfox-bin </blockquote> Swiftfox seems to crash on me a lot, so I&rsquo;ve unfortunately had to use this command a lot lately. – Main.FredPettis - 2012-05-29

killaprocess.txt · Last modified: 2013/01/28 04:29 by 127.0.0.1