There will be a situation when the Linux process becomes unresponsive. If your system is running too many processes in the background, you may experience the operation’s slowdown, or in some cases, the function will get freeze. In a such situation, the only way to get out of the problem is to use the Linux kill process.
In Linux, applications have their methods to kill the running app. It will automatically shut down the running process and solve the issue by itself.
However, in some cases, the processes may malfunction and continue without stopping. If you find any background running process that is causing the problem, the only way to stop is to kill the process using the command-line.
How to locate the process that causing the problem?
The first step of killing the Linux process that runs in the background is to find which application is causing the problem. There are two commands you can use the identify the process which is
top is the vital command that every administrator should be aware of the top command list all the currently running process.
You can find the relevant process ID(PID) which is unique to each process from the PID column as highlighted in the above image.
ps command is a versatile tool when combining with the grep. you can filter out specific processes connected to a program. If you want to filter out all the processes that are associated with the Firefox web browser, you can filter them out as below.
$ ps aux | grep -i firefox
In this example we have used couple of flags with ps command.
- a: display processes associated with all the users
- u: show process owner/user
- x: show processes not attached to a TTY/ terminal
Find the PID of each process as the 2nd value of each row. We have excluded the last raw because it is associated with our last command and it has no connection with the firefox processes.
Step by Step guide for killing the Linux process
- Once you have information on which line is causing the problem or unresponsive. The next step is getting the details.
- You need two pieces of information to run the killing process on Linux. Those are
- Process name
- Process ID (PID)
- You can execute the
killcommand with process ID or the
killallcommand with the name.
The good thing about the process kill ID function is that you do not have to remember all the names and various signals. You can apply the kill command to kill the process.
|1) SIGHUP||2) SIGINT||3) SIGQUIT||4) SIGILL||5) SIGTRAP|
|6) SIGABRT||7) SIGBUS||8) SIGFPE||9) SIGKILL||10) SIGUSR1|
|11) SIGSEGV||12) SIGUSR2||13) SIGPIPE||14) SIGALRM||15) SIGTERM|
|16) SIGSTKFLT||17) SIGCHLD||18) SIGCONT||19) SIGSTOP||20) SIGTSTP|
|21) SIGTTIN||22) SIGTTOU||23) SIGURG||24) SIGXCPU||25) SIGXFSZ|
|26) SIGVTALRM||27) SIGPROF||28) SIGWINCH||29) SIGIO||30) SIGPWR|
|31) SIGSYS||34) SIGRTMIN||35) SIGRTMIN+1||36) SIGRTMIN+2||37) SIGRTMIN+3|
|38) SIGRTMIN+4||39) SIGRTMIN+5||40) SIGRTMIN+6||41) SIGRTMIN+7||42) SIGRTMIN+8|
|43) SIGRTMIN+9||44) SIGRTMIN+10||45) SIGRTMIN+11||46) SIGRTMIN+12||47) SIGRTMIN+13|
|48) SIGRTMIN+14||49) SIGRTMIN+15||50) SIGRTMAX-14||51) SIGRTMAX-13||52) SIGRTMAX-12|
|53) SIGRTMAX-11||54) SIGRTMAX-10||55) SIGRTMAX-9||56) SIGRTMAX-8||57) SIGRTMAX-7|
|58) SIGRTMAX-6||59) SIGRTMAX-5||60) SIGRTMAX-4||61) SIGRTMAX-3||62) SIGRTMAX-2|
|63) SIGRTMAX-1||64) SIGRTMAX|
Frequenlty used signals are
- SIGKILL 9 ( kill the process forcefully)
- SIGTERM 15 ( terminate the process )
In the next step, run the command to kill the PID. In a few seconds, all the commands will be executed, and the given PID will be successfully eradicated.
$ kill -9 PID
$ kill -SIGKILL PID
There is a shortcut route as well to kill all the commands at one go. If you know the process’s name, you can use the
killall command and send the signal to kill all the process associate with the name
$ killall -9 firefox
$ killall -SIGKILL firefox
$ killall -15 firefox
$ killall -SIGTERM firefox
As you can see with the above examples, ending the Linux background process is not that difficult. You may have to practice them several times to understand the name and ids or get them using the Linux commands. Once you understand the fundamental process, running a Linux command is easy.
What is the reason behind the unresponsive process in Linux?
The Linux is built with vast small processes. Every process in Linux has its significance. Each process supports the core functionality of Linux, giving it the required flexibility and enables the users to perform the task seamlessly.
When there is a background process running with many other procedures simultaneously, the chances of malfunction in the process are high. Small changes to the time and interaction of the code with another running program produce the error.
In many cases, the Linux program rectifies the error and fixes it before it affects the program. Therefore, the majority of the time, these Linux programs are not detectable.
However, in some case, the program becomes unresponsive and throw an error or freeze the program. Once the program is stuck, you will not be able to perform any task. The only way to get out of this problem is the kill the process using the Linux command.
Key takeaways of terminating a Linux Process
1) If the process becomes unresponsive, the only way to kill them is to use the manual kill command.
2) In the beginning, you have to find the process, top, ps, pidof, or pgrep commands.
3) When you have detected the process using the above method, the next step is to use the kill command such as killall, pkill, kill, xkill, or top commands.
4) Use the predefined termination signals such as SIGHUP, SIGKILL, OR SIGTERM.
5) Remember that you must have the sudo privileges to kill other users processes.
We have tried to give you a simple solution to the Linux kill process. However, there are several ways that you can use to kill the process in Linux.
You should learn these commands as there will be several incidents when you may have to run the Linux termination commands on your system.
If you are into system management and administration, then termination of the process would help you save resources.