In this guide, you'll learn how to use the
killall command to end running processes on Linux. You'll also be given various examples that you can apply to your own system.
- How does the
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux disto|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
How does the killall command work?
killall command kills a process by name. For example, if you have a SSH daemon (which runs under the process name of
sshd) on your system and need to end it, the following command would be used.
$ sudo killall sshd
If you have multiple processes under the same name, all of those processes will be terminated, hence the all in "killall." Note that you need to match the name exactly, unlike with the
The command will try to terminate processes as gracefully as possible. By default,
killall sends a SIGTERM signal to the process, which is a polite way of shutting it down. This gives the process time to wrap things up and go through its shutdown procedure, rather than just terminating immediately.
If you find a process particularly stubborn, you could opt to send a SIGKILL signal instead. This forces a program to terminate instantly. But it should only be used in situations where a process has become unresponsive and refuses to close.
To send a SIGKILL signal to a process, use the following syntax:
$ sudo killall -9 sshd OR $ sudo killall -s KILL sshd
-s option in the example above allows us to specify the type of signal we wish to send. Type this command for a full list of signals:
$ killall -l HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
kill command pretty much has the same list, and also shows you what numbers correspond to which signals (that's how we used
-9 in one of the examples above).
killall command examples
We saw the basics above and now we know how the command works. But what else can it do? Take a look at the following examples.
Verify a process has actually ended by using the
-w option. This will cause the
killall command to wait for the process to end before it exits and returns you to the terminal prompt.
$ sudo killall -w sshd
Kill processes that are older than a certain age with the
-o option. The units are s,m,h,d,w,M,y for seconds, minutes, hours, days, weeks, Months and years respectively. Consider the following examples:
$ sudo killall -o 5m sshd # kill processes older than 5 minutes $ sudo killall -o 2w sshd # kill processes older than 2 weeks $ sudo killall -o 1M sshd # kill processes older than 1 month
Kill processes that are younger than a certain age with the
-y option. Same syntax as the above command. Examples:
$ sudo killall -o 5m sshd # kill processes newer than 5 minutes $ sudo killall -o 2w sshd # kill processes newer than 2 weeks $ sudo killall -o 1M sshd # kill processes newer than 1 month
Kill all processes owned by a user with the
-u option. This can, of course, be combined with the other options and you can also choose to specify a process name here or leave it blank to kill all processes under that user.
$ sudo killall -u linuxconfig OR $ sudo killall -u linuxconfig sshd
Now you know the basics of the
killall command and how it differs from its close cousins,
pkill. It definitely comes in handy but it's important to know that all three of the kill commands have their own niches. Knowing when to use the right one is an important skill. Be sure to check out the man pages for a few more obscure options.