2-Minute Linux Tip: How to terminate processes

Network World | Apr 24, 2018

In today’s tip, I’m going to show you how to terminate processes on Linux systems using kill, pkill and killall and show you why it makes a difference which command you choose.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In today’s tip, I’m going to show you how to terminate processes on Linux systems using kill, pkill and killall and show you why it makes a difference which command you choose.
So, let’s go to your terminal window and see how this works.
For a simple kill, use a command like ps -ef to display running processes and grab the process ID for the one you want to stop.
$ ps
Say you want to kill that badproc there. Easy. Use kill followed by the process ID and you’ll be done:
$ kill #####
That works, but you could have made this even easier on yourself had you used the pkill command. pkill kills a process “by name”. You could have done this instead:
$ pkill myloop
You could also use the killall command:
$ killall myloop
And both pkill and killall will kill more than one process if more than one is running.
The primary difference between pkill and killall is that pkill allows you to kill a process using only a portion of its name. So this killall command fails to terminate the process:
$ killall bad
while this command succeeds
$ pkill bad
The killall command is less likely to terminate processes that you didn’t intend to kill, but requires a little less typing. The kill command requires more work, but only kills the process that you specify by PID.
That’s your Linux tip for today. If you liked this video, hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.