Which of the following commands can be used to terminate a process by the process name?

Apr 28, 2022

Edward S.

3min Read

Which of the following commands can be used to terminate a process by the process name?

Tasks in Linux are called processes. Every process has a unique process ID. In this tutorial, we’ll show you how to terminate a process using Linux commands, to improve your VPS management skills.

Download Complete Linux Commands Cheat Sheet

  • What Is Kill Command Used For?
  • How to Show the Process ID in Linux
  • How to Show All Kill Command Signals
  • How to Kill a Process in Linux Using the Terminal
    • Using the Kill Command with a PID
    • How to Kill Multiple Processes in Linux
    • How to Kill a Process in Linux Using the Pkill Command
    • How to Kill a Process in Linux Using the Killall Command

What Is Kill Command Used For?

Sometimes, you might start a server or an application, forget about it, and need to shut it off. In such scenarios, we can use the kill command.

Below are a few examples where the kill command can be helpful:

  • To stop any automated process
  • To stop a process that has been started by accident
  • To stop a process that consumes a lot of memory
  • To force stop any process running in Linux
  • To stop a background process

Apart from stopping a process, the kill command can provide several features. Like, send a signal to a process. By default, this is taken as a TERM signal which will terminate the process.

How to Show the Process ID in Linux

Kill commands lets you terminate a process by using a specific process ID, also known as a pid. To show a pid in Linux you can execute the following command:

ps

This will list all the available processes with a pid. If you want to make your list more specific – add a grep command like this:

ps -ux | grep java

This will display all java processes running in the output.

How to Show All Kill Command Signals

There are multiple signals available in Linux which can be used to interrupt, terminate, or pause processes. The command can be used as below:

kill -l

This command will display a manual page entry of the different kill signals with their names and corresponding numbers. While there are multiple signals available, in most cases we would use SIGKILL (9) and SIGTERM (15).

How to Kill a Process in Linux Using the Terminal

Now we’re ready to move on and learn all the different uses of the Kill Command. To follow along, access your virtual private server using SSH.

Using the Kill Command with a PID

To kill a specific process with a PID use the following command:

kill 63772

Here 63772 is the pid for a process we want to terminate. Since no signal is specified this will be SIGTERM signal. Sometimes, this may not work; in that case, you may have to kill a process forcefully.

In such cases, you can use the command format as shown below:

kill [Signal_or_Option] pid

Below is a sample command to forcefully kill the process:

kill SIGKILL 63772

Similarly, to kill using the shorter option you can use:

kill -9 63772

Replace 63772 with the relevant pid for the process to be terminated.

How to Kill Multiple Processes in Linux

With the same command, you can kill multiple processes. The syntax for this command would be:

kill -9 pid1 pid2 pid3

Here’s an example showing how it would look in the real world:

kill -9 63772 45116 23465

How to Kill a Process in Linux Using the Pkill Command

Pkill is a flavor of the kill command where you can specify the process name or a pattern to find a process:

pkill chrome

The above command will kill the chrome browser. You can also specify a partial name match in the command line such as:

pkill chr

However, this command carries a risk of sometimes killing the wrong process, especially when there are multiple processes with the same name.

You can check the list by using the complete process name:

pidof chrome

The above command can be used when you know the complete name of the process.

You can check for matching processes by using a partial name:

pgrep -l chr

This command will list the process with the corresponding process ID.

How to Kill a Process in Linux Using the Killall Command

The basic difference between killall and kill is that killall can terminate the process by name while the kill command uses the pid.

An example of such command is:

killall chrome

This is similar to pkill. However, killall does an exact name match, while pkill can do a pattern match. This is one of the reasons, killall is safer compared to pkill.

One more difference is the root package to which these commands belong. In Linux, killall belongs to the psmisc package. On the other hand, commands such as ps, top, kill, pkill belong to procps package.

Another difference is that killall can be customized to terminate processes based on timestamps. In case you want to kill a process that has been running for less than 40 minutes, then you can use:

killall -y 40m [Process_Name>]

You can similarly use the below options together with the killall command:

  • s – seconds
  • m – minutes
  • h – hours
  • d – days
  • w -weeks
  • M – months
  • y – years

Conclusion

This covers the most important and useful kill commands. To further learn about this essential utility you can refer to the Linux manual. Good luck with your project, see you in the next tutorial!

Edward is a Content Editor with years of experience in IT as a writer, marketer, and Linux enthusiast. Edward's goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.

Which of the following command can be used to terminate a process by the process name?

The killall command is used to kill processes by name. By default, it will send a SIGTERM signal.

What is kill PID command?

Description. The kill command sends a signal (by default, the SIGTERM signal) to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in the ProcessID variable.

How do you kill a process by ID pkill?

How to Terminate a Process ( pkill ).
(Optional) To terminate the process of another user, become superuser or assume an equivalent role..
Obtain the process ID for the process that you want to terminate. $ pgrep process. ... .
Terminate the process. $ pkill [ signal ] process. ... .
Verify that the process has been terminated..

How do I stop a process in terminal?

You can run a process with ⌃R (macOS), or Shift+F10 (Windows/Linux). To stop a process, you can use ⌘F2 on macOS, or Ctrl+F2 on Windows/Linux.