2 Ways to Kill Linux Processes

Linux provides two common signals available in the command line to kill a process: SIGKILL and SIGTERM. Learn more about them and how to use them to kill a Linux process.

Linux

When an application is frozen on a Linux machine, it could cause other issues. You can use the command line utility to manually terminate the process behind the application to free up resources and return the machine to its original state. Every process is assigned an ID, and you can kill the Linux process once you have the ID.

2 Most Popular Ways to Kill Linux Processes

Applications in Linux constantly communicate with the underlying operating system. The operating system or users can send interrupt requests to an application. Interrupts can be ignored or handled, depending on the type of signal. Linux provides two common signals available in the command line to kill a process: SIGKILL and SIGTERM.

Before you kill any process, you first need its ID. Linux contains a process table with every process ID running on the system, and you can use this table to find an application process ID that’s causing issues. Type the following command into your Linux terminal where <application name> is the name of the malfunctioning application:

Output from the above command displays the process ID behind the application. For example, suppose that you want the process ID for the gedit program. The following command would display the application’s process ID:

What Is SIGKILL (Signal 9)?

SIGKILL is a last resort when an application does not respond to any input. When an application receives the SIGKILL signal, it shuts down and does not perform any cleanup procedures. Because the application does not perform any cleanup operations, it can have unintended consequences, but it can free up resources when you have no other options. SIGKILL also does not give the application the opportunity to send messages to parent or child processes to let them know that it’s closing, leaving zombie processes in the table. Constant use of SIGKILL to terminate a process indicates that there’s a bug in the application.

What Is SIGTERM (Signal 15)?

Using SIGTERM is a preferred method to prematurely terminate a process. SIGTERM lets the application clean up, but it can be ignored by the application. An application receiving a SIGTERM signal has time to let child or parent processes know that it’s closing, so it’s a much cleaner way of stopping a process. Because data can be cleaned up, it’s much less likely that you’ll have unintended negative consequences after using SIGTERM.

How to Kill a Linux Process with SIGKILL

If you’ve determined that the best way to kill a process is using SIGKILL, then open the terminal and type the following into the command line where <process ID> is the ID you obtained using the pidof command:

For example, suppose that you retrieved a process ID of 5643 from the process table. The following command would send a SIGKILL signal to the process:

How to Kill a Linux Process with SIGTERM

Killing a process using SIGTERM uses the same command as SIGKILL, but you leave out the optional signal parameter. The following command sends a SIGTERM signal to the process ID 5643:

Note that without the optional signal parameter, the default is SIGTERM.

What Is the Best Way to Kill a Linux Process?

Although SIGKILL should only be used as a last resort, sometimes you have no other choice. It should be used if you receive no response from the application and no other interaction with the application works. A process has the option to disregard a SIGTERM signal, but you should first try to use SIGTERM since it allows a process to clean up before terminating. After you try SIGTERM, then it’s reasonable to use SIGKILL.

What to Do When a Process Won’t Die

If SIGKILL does not work, try again. It’s possible that the operating system is experiencing errors, and it could mean that the entire system needs a reboot. Before performing a system reboot, try to kill any other unresponsive processes before finally performing a hard reboot.

Related reading: Task vs. Process in Linux and When to Use the –force flag in Linux

Try Out FlashBlade