killall in Ubuntu

In this article, we would cover killall command-line utility in Ubuntu. In previous article, we saw how to kill a process using kill command-line utility. With kill we have used a Process ID (PID) to terminate a process. With killall, we use the Process name instead of a PID.

Syntax –

killall [option] <process_name>

We need to take extra care with killall because as the utility name suggests, it may terminate lot more processes than we intend to.

For instance, if some process is running in both background and foreground. And, if we forget that we have a background process. Then, using the killall will terminate the both. Although, we didn’t want to kill the background process but still it got terminated.

killall in Ubuntu

Let’s understand the above with the help of an example. We are working on two text files with nano editor –

nano test1 &
nano test2

One of the above (with &) runs as background process. Use the following to see the background process –

jobs -l

It would return with –

[1]+ 7814 Stopped (tty output) nano test1

Now, we want to kill nano process using killall (run the utility in another tab). And, we aren’t aware of the background process. Then,

killall -9 nano

We would receive the message –

Killed

for the background jobs, it would return –

[1]+ Killed nano test1

Furthermore, the default signal for killall is SIGTERM (Terminate signal) or 15. 9 is for SIGKILL(Kill signal).

SIGTERM kills the process gracefully, But, SIGKILL would end it abruptly.

In conclusion, we have discussed how to terminate a process in Ubuntu using killall command-line utility.

Additional Info –

Use -i option to make killall interactive. That is, it asks for a confirmation before it terminates a process –

killall -i <process_name>

To list all known signal names –

killall -l

The make killall case-insensitive or ignore case then,

killall -I <process_name>

Similar Posts