Several methods may be used to kill a process—also referred to as a task—on Linux, most of which involve running commands in the Terminal. Kill is the basic commands used to kill processes in various Linux distributions.
This command needs to be executed along with the ID, or PID of the process you want to terminate. Kling a process on Linux is essentially forcing it to shut down when it malfunctions. This may be necessary when a process gets into a tight computational loop, causing it to become unresponsive.
An error in the processing schedule may also cause a process to hang on Linux. In either case, you need to manually terminate the process to prevent it from using too many resources on your system. Throughout this guide, you will learn how to list, and identify a process as well as several ways of terminating processes on Linux.
What is a Process on Linux?
Also referred to as a task, a process is the running form of a program on your Linux distro. While programs are stored on the hard disk, processes run in the memory of your computer. Basically, processes tend to have a ‘parent-child’ relationship, and a single process can spawn multiple ‘children’.
While several processes may run parallel to each other, each process has its own life cycle, and should automatically terminate itself when completed or closed. Linux processes may be grouped into two broad categories:
These are the processes that are started/launched by the user. They usually run on a Terminal window or are displayed on a graphical application on your desktop.
These are automatically started by the system whenever they are required. As a user, you have no interaction whatsoever with the processes on the computer background. Neither do background processes require user input, nor do they present any output or results.
Background processes in Linux include services and daemons. For you to kill a process on Linux, you need to have the right information, including its signal, and PID.
How to Locate a Process on Linux
Regardless of the Linux distribution, you are using, you first need to access the process information, before you can forcibly terminate it. There are several commands you can run on the terminal to display/list the process along with the information you require to kill it, including:
Locate the Process using the ‘PS’ Command
Running the process status (ps) command on the terminal will list the processes that are associated with the shell on your Linux PC. To do this, run the following command on your terminal:
The results you get after running this command will include such information as the PID, the cumulative extraction time (TIME), terminal identifier (TTY), and command name (CMD). Several options may be applied to the ps command to filter the results even further or bring up additional information.
Some of the options commonly used with the ps command on Linux include:
a: Displays information on all the recently requested processes, except the group leaders. This option will also not show results for the processes associated with the terminal itself.
u: This option only displays the processes used by a particular user
x: Running the ps command with the x option will display all the processes. Without the X option, the results will not include the GUI process.
e: used to display information on every process, including the ones that are currently running
f: An option that may be used to display the complete listing
i: Use this option with the ps command, if you wish to generate a long listing
Locate Processes Using the ‘top’ Command
You may also run the top command on the terminal to get a list of all the processes that are currently running on the Linux distro. This command displays detailed information for each process, including PID, CPU usage, username, executed command, and time.
To locate a running process, run this command on the terminal as follows:
You may browse through the displayed information by scrolling up or down on your terminal. This command also supports several filters to help you narrow the results down. For instance, it allows you to narrow the processes down by CPU usage, or name, among other parameters.
If you want to exit from the top section, just press the ‘Q’ key. This operation will take you back to the terminal. Alternatively, you could press the Ctrl + C keys combination to exit.
List All Processes on Linux
To display all processes in your Linux-based operating system, run the ps command, alongside the aux option. In this regard, you need to execute the following command:
The output for the ps command is similar to that of the top command on Linux. However, you will find the ps command to be more useful as it allows you to filter the results using the grep option. With the ps aux command, you will get the full command line for every process displayed.
You may also filter the ps aux command results using several other parameters like grep, and javatpo+. ‘Grepping’ the ps aux command on Linux will show anything in the path, or even the parameters of a process’ binary. To filter the processes with javatpo+ as the username, run the following command:
ps aux | grep javatpo+
List All Processes Scheduled to Run on Linux
If you wish to view all the processes that are scheduled to run on your Linux PC, you need to run the following command on the terminal:
# ps -ef | more
The results will have such information as the username running the process (UID), Unique process identification number (PID), and the parent process identification number (PPID). Running this command will also reveal the time the process was started, (STIME), command name (CMD), cumulative execution time (TIME), and its controlling terminal (TTY).
If the process started without the use of a terminal, the system process (daemons) will only display a question mark (?).
Locating a Process Using the pidof, and pgrep Commands
Executing the pidof command on a Linux terminal allows you to locate a process as well as track a process by its name. When run along with the process name, this command will reveal the PID of the relevant process. If you only want to know the PID of a process, execute the command as follows:
If the process in question was Chrome, then the command would be pidof chrome.
What is a Kill Command on Linux?
In Linux, the ‘kill’ command is a line utility that may be used to forcibly close a process. Normally, the command is a shell built-in. This essentially means that the command is called from the user’s she’ll as opposed to an external executable program.
When executed, a kill command sends a TERM signal to the associated process, requiring the process to perform any required cleanup before shutting down. In addition to terminating processes, this command may also be used to restart processes on Linux.
What Processes Can You Kill on Linux?
Regardless of the method or command, you are executing, there are scenarios when you just cannot forcibly close a process on Linux. In this regard, here are some of the things you need to note beforehand:
User Type Restrictions
If you are logged as a normal user, Linux will only allow you to kill the processes that you started. In this case, the system will not allow you to terminate processes initiated by other users on the same computer. The ps aux and top commands will display users running similar processes, but you will not be able to terminate their processes.
A root user has the privileges required to kill any process on the computer, including the processes initiated by other users. If logged in as a normal user, adding sudo before any command will also allow you to execute it as a root user.
Type of Command Signal Sent
Whenever you execute a kill command on Linux, a signal will be sent to the associated process. Several signals may be sent in such a case, but most Linux distributions only support SIGTERM and SIGKILLS signals by default.
The SIGTERM is sent when you wish to terminate a process gracefully. If you wish to terminate a process by force on Linux, the SIGKILL signal will be sent instead.
Process State Restriction
Regardless of the distribution, you are using, Linux will keep the state of a process until it is completely removed from the system. As such, the child process will continue to show in the process list, until the parent process is deleted.
Linux processes that are in ‘Uninterruptible Sleep’ status cannot be terminated. A process is considered to be in this state when carrying out an input/output operation. After executing either the ps aux or top command on the terminal, the process state will be displayed on the 8th column of the results.
How to Terminate a Process on Any Linux Distribution
Linux-based operating systems allow you to close problematic processes in several ways. You may decide to run a series of commands on the terminal, or just end the process from the System Monitor app.
Discussed below are some of the most effective methods you may apply to kill a process on any Linux distribution:
Method 1: How To Kill A Process In Linux Ubuntu (Using the System Monitor)
If you are not comfortable running commands on the terminal, you may also kill a process from the System Monitor—a graphical environment in Linux Ubuntu. This tool may be compared to the Task Manager in Windows.
In its functioning, the System Monitor lists all the running processes, and displays real-time information on the RAM, CPU, and disk usage. Follow these steps to kill a process from the system monitor:
Step 1: Launch the System Manager on Linux
Click on the ‘Show Applications’ button towards the bottom of the Ubuntu dock.
From the list of applications displayed, click on the System Monitor icon to launch it. By default, it should open showing the Processes tab. If not, just click on the Processes tab at the top of the window. Scroll down the displayed list of processes to find the process/processes for the problematic app.
Step 2: Kill the Process
Once you locate the process, right-click its entry, and then select the Kill option from the context menu. Alternatively, you could just click on the entry to select it, and then press the ‘End Process’ button—situated at the bottom of the window.
You will be prompted to confirm the ‘end running process’s operation. Just click on the ‘Kill Process’ option to confirm the operation. The process should automatically disappear from the Processes list on your System Monitor.
If the process was for an app that was still open on the desktop, the open window will also close. If this method does not work, you should consider using the terminal instead.
Method 2: Terminate a Process on Linux Using the Kill Command
If you are having a hard time closing an app or killing a process using the System Monitor, you should execute a kill command on the terminal. The kill command sends signal 15 that is designed to terminate a process in a controlled manner.
To do this, press the Ctrl + Alt keys combination to launch the terminal. To execute the kill command successfully, you first need to find out the PID for the process you want to close. This can be accomplished by executing either the pgrep or ps command, as elaborated above.
Once you have the process PID, execute the following command in the terminal you just opened:
Kill [PID Number]
If the PID for the process happens to be 5296, then the right command would be to kill 5296. It is also possible to terminate several processes simultaneously using the kill command. In this case, you need to enter multiple PIDs for the processes you wish to end on a single command line.
Method 3: How to Kill a Process in Linux Without the PID
In most cases, you will not know the PID for the process you wish to close off the head. In other cases, a lookup for the PID will not yield results. Even so, you may still close a process in Linux without the PID. In this regard, you need to execute the pkill command.
Instead of the process ID, you will be required to enter the process name along with the pkill command. Press the Ctrl + Alt keys simultaneously to launch the terminal. You should then execute the following command:
pkill [process name]
Alternatively, you could apply the pgrep command to ascertain the correct process ID before closing it, as follows:
pgrep [process name]
Once you have obtained the PID for the problematic process, you need to execute the following command on the terminal:
pkill [process ID]
In both cases, the system will kill the process and shut the associated app down in less than five seconds.
Method 4: Linux Kill All Processes by User
If the above-discussed methods do not seem to work, you should consider ending all the running processes by the current user. To do this, you need to execute the kilall command on the Linux terminal. This command is meant to kill all the currently running processes for a particular App or program.
Are you having a problem closing the Firefox browser using the above-discussed methods, chances are that several other Firefox processes are still running. Executing the killall command alongside the application name will kill all the running processes for the app.
In the case of Mozilla Firefox, you should execute the following command on the terminal:
You should only use this command in cases where the others have failed. The processes may also fail to terminate because you are not signed in as the root. In such a case, you should add sudo ahead of the command for it to execute successfully.
Method 5: How to Forcibly Kill a Process in Linux
There are times when the default signal 15 that is meant to kill processes fails to work. If the process you want to close is not responding to signal 15, you may need to close it by force. Instead of signal 15, you need to execute a command that sends signal 9.
The correct syntax for such a command would be:
kill -9 PID
pkill -9 [process name]
Method 6: How to Kill a Process on Linux Ubuntu Using a Keyboard Shortcut
You can still terminate a process on the Ubuntu operating system without having to run all these commands. To save time while closing unresponsive applications, you should consider setting up the appropriate keyboard shortcut.
This method will also require you to execute the xkill command as well. To set up a keyboard shortcut for terminating processes navigate to the Ubuntu Settings menu. Select the Keyboard option from the settings menu, and then choose ‘ Custom Shortcuts’.
Now click on the + icon to create a new shortcut. Type in xkill for both the Command and Name fields and then click the Apply button. Select your preferred shortcut from the list of keyboard shortcuts displayed. You only need to press this shortcut every time you need to terminate a process on Linux.
Similar to Windows, you only need to click on the X icon on a Linux window to close it. However, there are cases when applications and programs fail to respond to this conventional method. In such a case, you need to manually terminate the currently running processes for the application.
You may use the System Monitor to forcibly shut the application down. Alternatively, you need to run appropriate commands using the terminal on Linux. Some of the commands will require you to ascertain the correct PID for the process you wish to terminate beforehand.
You can execute the pgrep or ps commands to get the PID information. To terminate the process, you may run the xkill, kill, pkill, or killall command on the terminal. In either case, this guide will help you terminate any process on any Linux distribution.