Imagine: you run a program, work with it, and after a while it stops responding and hangs. It is not possible to restart the application due to the fact that its instance is still hanging in the computer's memory. What to do in this case? First of all, you need to exit the program and remove the process from memory.
The easiest and most versatile way to kill a process in Linux is to use terminal commands. This option will work on any Linux distribution.
Linux processes
In the Linux operating system, a process is usually a running program or application. Also, a process can be called any task that is currently running under Linux. Any running process can start a child process.
All processes running on Linux have the following attributes:
- PID - unique identifier for each process.
- PPID - parent process ID.
- ID of the user who started the process.
- Priority.
- Process status.
Each running process is in one of the following states:
- "In progress". The letter R is used to represent this state.
- A process that has started a system operation, such as input or output, and is waiting for it to complete is called "Waiting". Designated with the letter S.
- A process that is stopped by the user or Linux OS is in the "Stopped" state. This state is indicated by the symbol T.
- "Zombies" are processes that are no longer running, but consume operating system resources. Designated with the letter Z.
- A persistent process cannot be terminated until the DMA operation has completed. The process is denoted by the symbol D.
Search process
Before you can kill a process in Linux, you must first find it. The most commonly used Linux commands for this purpose are top and ps.
Using the top command
The top command displays a complete list of current processes. In addition, the list contains a lot of useful information about each running process, for example:
- PID - unique process number;
- USER - login of the user who launched this process;
- PR - process priority at a given time;
- NI - priority assigned to the process by the NICE command;
- S- state of this process;
- %CPU- how much CPU time this process takes (in percent);
- %MEM - the amount of RAM thatoccupies this process (in percent);
- TIME+ - how much time has passed since the process started;
- COMMAND - the program that started the process.

The information provided by the top command is sorted by the amount of CPU time used (%CPU column). The user can change the sort order:
- sort processes by amount of occupied RAM (%MEM column) you need to press the key combination Shift+M;
- sort by process number (PID column) using Shift+N;
- sort by working time (column TIME+) - Shift+T.
- return to original sorting by CPU load - press Shift+P.
Using the ps command
The top command can get you a lot of information, but it's not the most convenient way to get the information you need about the process you need. To avoid looking for the desired process, you can use the ps command and filter the list using the greep command. For example, if you want to find all the processes associated with the running Opera browser, you can type ps axu | grep Mozilla.
The ps command has the following options:
- a - show processes for all users;
- u - display the user who is the owner of the process;
- x - show processes that are not attached to the terminal. This option is important when searching for information about a graphical application.

With the help of a bunch of ps and grep commands, you can get all the information you need to kill a hung application.
Other ways to search for a process
To find the PID of a process by its name, there is the pidof command. The format for using it is: pidof+program name. For example, to find all the PIDs related to the Opera program, you would type: pidof Opera.
In some cases, it happens that the program has completed its execution, but has not released the network port. To get information, in this case, you need to enter the fuser command: fuser -vn tcp 80. Where 80 is the number of the hung port. After that, you can kill the Linux process by port.
Ending a process with the kill command
After you know the PID of the process and its name, you can proceed to the operation of terminating an unnecessary application. Two commands are used for this: kill - kill the process by id in Linux and killall - end the program execution by name.
Kill command structure: kill SIGNAL PID. Where SIGNAL is the signal to be sent and PID is the process ID.

The SIGNAL parameter for process termination is 9 (SIGKILL). Thus, in order to kill a process by pid in Linux, you need to enter the command in the console: kill -9 9578. Where 9578 is a unique process number.
The process termination command is not the only one that can be sent using the kill system application. Get a list of all commands that can be sentcommand with kill, you can enter the command kill -l.

It's also useful to know the other values that the SIGNAL parameter can take. For example, you can use the HUP option to reload a frozen program. The SIGTERM signal does not interrupt the program immediately, but gives time for graceful shutdown, i.e. the application saves data, terminates its execution, and releases all occupied resources.
How to kill a process by name in Linux
If you know the name of the program to be terminated, you can use the killall command. For example, to kill all processes related to the Opera application, you need to enter the command: killall -9 Opera.

True, this command does not always end the processes related to the program being destroyed. If after running the above command you type ps aux | grep Opera and you will see that some processes are still running, it is best to kill them with the kill system application.
In some cases, in order to kill a process running by another user on Linux, root privileges may be required. Then, before the process termination command, you need to enter the sudo command.
That's all the information a user needs to manage processes. True, this topic is not easy for beginners, but you need to master it, since all actions of the operating system are carried out using processes. To learn how to manage them, you need a littlepractice.