The “killall” Command in Linux [6+ Practical Examples]

When any program has crashed or is stuck, the killall command in Linux helps us in such situations. One can easily terminate all processes with the same name using the killall command. In this article, I will demonstrate various applications and practical examples of the killall command in Linux.

A. Description

The killall command in Linux can terminate any program in case of unresponsiveness or a program crash.

B. Syntax

The killall command in Linux is a command that takes OPTIONS and process_name as its argument. The general syntax for the killall command is given below.

killall [OPTION] process_name
Note: Here, the OPTION is enclosed by square brackets, meaning that specifying an OPTION is not mandatory for the command.

C. Options

You can add an option to the syntax of the killall command to modify it. I have listed some useful options below. If you do not find your desired option here, you can look for it on the man (manual) page. To go to the man page, type the following command and press ENTER.

man killall

Useful Options

  • -I/–ignore-case: Performs the task where case insensitive process name match.
  • -g/ –process-group: It kills the process group to which the process belongs. The kill signal is only sent once per group, even if multiple processes belonging to the same process group are found.
  • -i/–interactive: It asks interactively for confirmation before killing a process.
  • -l/ –list: It prints a complete list of all known signal names.
  • -o/–older-than: It matches only processes that are older (started before) than the time specified. The units are s,m,h,d,w, M,y  for seconds,  minutes,  hours, days, weeks, months, and years respectively.
  • -q/ –quiet: It does not complain if no processes were killed.
  • -r/–regexp: It interprets process name pattern as a POSIX extended regular expression, per regex(3).
  • -s, –signal/-SIGNAL: It sends this signal instead of SIGTERM.
  • -u/–user: It only kills processes the specified user owns.
  • -v/–verbose: It reports whether the signal was successfully sent.
  • -V/–version: It displays the version information on the terminal.
  • -y/–younger-than: It matches only processes that are younger (started after) than the time specified. The units are s,m,h,d,w,M,y for seconds,  minutes,  hours,  days, weeks, Months, and years respectively.
Note: All options in Linux are case-sensitive. Therefore, You must be careful while using these.

Practical Examples of the “killall” Command in Linux

The killall command in Linux is a helpful tool for terminating a process in the case of unresponsiveness. The killall command in Linux has many practical applications, and I have illustrated a few of them in the following examples.

Example 1: Terminating a Process by Filename Using the “killall” Command in Linux

You can easily terminate a process in Linux using the killall command followed by the process name. The following image shows that firefox is currently running in the background of my device. Firefox is currently running in the background of my device. Now, I will terminate the firefox process using the killall command. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

killall firefox

➌ Now, press the ENTER button.

➍ Copy the following command to check whether the firefox application has been closed:

top -n3 | grep firefox

➎ Press the ENTER button again.

Output >

The following image shows that I have successfully closed the firefox process by using the killall command in Linux, So, no PID of firefox is printed in the terminal.The firefox process is successfully closed by the killall command in Linux, so no PID of firefox is printed here.


Similar Readings


Example 2: Terminating Multiple Programs Using the “killall” Command in Linux

You can terminate multiple processes in a single command line. The following image shows that spotify and firefox are currently running in the background of my device.Spotify and firefox are currently running in the background of my device. Now, I will terminate both firefox and spotify. To do the same, follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the terminal.

killall firefox spotify

➌ Now, press the ENTER button.

➍ To get the process ID of spotify, run the following command in the command prompt.

top -n5 | grep spotify

➎  Press the ENTER button again.

➏ To get the process ID of firefox, run the following command in the command prompt.

top -n5 | grep firefox

➐ Tap the ENTER button again.

Output >

Both the firefox and spotify application are closed successfully using the killall command in Linux, as illustrated in the following image. That’s why no PID of spotify and firefox are printed in the terminal.The firefox and spotify application are closed successfully using the killall command in Linux. No PID of spotify and firefox are printed in the terminal.

Example 3: Terminating a Process Interactively Using the “killall” Command in Linux

Sometimes, you may accidentally pass any unwanted process name after killall command. To avoid any unwilling process termination, you can use the -i option after the killall command in Linux. The following image shows that firefox is currently running in the background.Firefox is currently running in the background. I will terminate the firefox process interactively using the -i option. To do so, follow the procedures below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the terminal.

killall -i firefox

➌ Now, press the ENTER button.

➍ Press Y when asked for confirmation.

➎ To get the process ID of firefox, copy the following command in the command prompt.

top -n5 | grep firefox

➏ Tap the ENTER button again.

Output >

In the next image, you can see that I have closed the firefox process after asking for confirmation by using the killall command in Linux. That is why no PID of firefox is printed in the terminal.The firefox process is closed after asking for confirmation by the killall command in Linux. That is why no PID of firefox is printed in the terminal.

Example 4: Terminating a Process with Case-Insensitive Process Name Using the “killall” Command in Linux

Anyone can make a mistake about the proper casing of a process name. However, the killall command in Linux with the -I option helps to terminate a process irrespective of the casing of that process name used in the command. The following image shows that firefox is currently running in the background.Firefox is currently running in the background. Here I will terminate the firefox process without using the proper casing. To do the same, follow the below steps.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

killall -I Firefox

➌ Now, hit the ENTER button.

➍ To get the process ID of firefox, run the following command in the command prompt.

top -n5 | grep firefox

➎ Press the ENTER button again.

Output >

The following image shows that I have successfully closed the firefox process using the killall command in Linux. For this reason, no PID of firefox is printed in the terminal.The firefox process is closed using the killall command in Linux. For this reason, no PID of firefox is printed in the terminal.

Example 5: Killing All the Processes Owned by a Specific User

When I multitask, it is hectic to terminate all processes I run manually. Here, the killall command in Linux helps me terminate all processes a user runs. The following image shows that firefox is currently running in the background. And the current user is susmit.Firefox is currently running in the background. And the current user is susmit.I will terminate all processes run by the current user susmit. To do the same task, follow the steps mentioned below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Run the following command in the command prompt:

killall -u susmit

killall -u susmit command is written in the terminal.

➌ Now, hit the ENTER button.

Output >

The following image shows that I have successfully terminated all the processes owned by the user susmit using the killall command in Linux, so the system sent me to the log-in page.All processes owned by the user susmit are successfully terminated using the killall command in Linux, so the system sent me to the log-in page.

Example 6: Killing Process by Mentioning Their Running Time

You can terminate all processes by specifying how long they are running for. Two options are available for this purpose.

  • -o/–older-than: This option matches only processes that are older (started before) than the specified time.
  • -y/–younger-than: This option matches only processes that are younger (started after) than the specified time.

Case A: Terminating All the Processes Which are Running More than the Specified Time

You can terminate all processes running for more than the specified time. Here I will terminate all the processes running for more than 1 minute. The following image shows that firefox is currently running in the background for more than one minute.Firefox is currently running in the background for more than one minute. To do the same, follow the steps mentioned below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

killall -o 1m firefox

➌ Now, hit the ENTER button.

➍ To check whether firefox is closed, execute the following command in the command prompt.

top -n3 | grep firefox

➎ Press the ENTER button again.

Output >

The following image shows that I have successfully closed the firefox process using the killall command in Linux. For this reason, no PID of firefox is printed in the terminal.The firefox process is successfully closed using the killall command in Linux. For this reason, no PID of firefox is printed in the terminal.

Case B: Terminating All the Processes Which are Running Less than the Specified Time

You can terminate all processes running for less than the specified time. Here I will terminate all the processes running for less than ten minutes. The following image shows that firefox is currently running in the background for less than ten minutes.Firefox is currently running in the background for less than ten minutes. To do so, follow the steps given below.

Steps to Follow >

➊ At first, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

killall -y 10m

➌ Now, hit the ENTER button.

➍ To check whether firefox is closed, insert the following command in the command prompt.

top -n3 | grep firefox

➎ Press the ENTER button again.

Output >

The firefox application is closed successfully using the killall command in Linux, as illustrated in the following image. That is why no PID of spotify and firefox are printed in the terminal.The firefox and spotify application are closed successfully using the killall command in Linux. No PID of spotify and firefox are printed in the terminal.

Conclusion

In this article, I have demonstrated the application and effectiveness of the killall command in Linux. After going through this article, I hope you’ll be competent enough to explore more about the killall command with the help of the illustrated practical examples.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Susmit Das Gupta

Hello everyone. I am Susmit Das Gupta, currently working as a Linux Content Developer Executive at SOFTEKO. I am a Mechanical Engineering graduate from Bangladesh University of Engineering and Technology. Besides my routine works, I find interest in going through new things, exploring new places, and capturing landscapes. Read Full Bio

Leave a Comment