How to use killall command on Linux

Posted by

  • How does the killall command work?
  • killall command examples

Use killall to end a process by name on Linux

How does the killall command work?

The 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

The all in “killall” refers to the fact that all processes running under the same name will be terminated. Be aware that, in contrast to the pkill command, you must match the name exactly.

The command will make an effort to end processes as politely as feasible. Killall’s default behaviour is to politely terminate a process by sending it a SIGTERM signal. This prevents the process from ending abruptly and allows it time to finish and follow its shutdown routine.

Instead, you might choose to issue a SIGKILL signal to any process that you find very uncooperative. This compels an application to end abruptly. However, it ought to be applied solely in cases where a process has grown inactive and won’t

To send a SIGKILL signal to a process, use the following syntax:

$ sudo killall -9 sshd
OR
$ sudo killall -s KILL sshd

The -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

Basically the same list is provided by the kill command, which also indicates which numbers match various signals (this is how we used -9 in one of the previous examples).

List of signals that can be sent by the killall command

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

Use the -o option to terminate processes that are older than a specified age. For seconds, minutes, hours, days, weeks, months, and years, respectively, the units are s, m, h, d, w, M, and y. Take a look at these instances:

$ 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

Utilise the -u option to end any process that is owned by a user. Naturally, this can be used in conjunction with the other settings. Additionally, you have the option to remove all processes associated with that user by leaving the field empty or entering a process name.

$ sudo killall -u linuxconfig
OR
$ sudo killall -u linuxconfig sshd

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x