Getting the processes information
Getting the unresponsive process is the first step in killing it. We can get the process information by using two commands, i.e., top and ps. To see a list of your running processes, type top from the command line:
Or
You will find some relevant details on the terminal. For instance, imagine a situation where the “Application” related process has become unresponsive. In our case, there are four instances of Applications running with Process IDs (PID) 5441, 3870, 5062, and 3637, 4233, 770, 3787, according to our top command display.
Although the top is extremely useful, it is not always the most efficient way to obtain information. Now let us say you need to kill the application processes, but you don’t want to get the real-time information from the top command. in this scenario, you can use the ps command. Furthermore, we can filter the output using the grep command. We are only interested in listing down the Application-related processes. Use the command given below to see the application related processes:
Whereas,
a = Show all user-related processes
u = Show the process’s the owner/user.
x = Show all the processes which are not terminal related
The grep prints lines that match a pattern, while ps returns a snapshot of a current process. The reason for using grep to filter ps is simple: if you run ps by itself, you will get a snapshot of all running processes.
Display list of Signals:
Type kill -l to display the list of all signals. We can send various signals with the kill command.
We can choose any signal from the list of given signals.
There are some common kill signals:
Signals name Signal value Effect
SIGINT 2 Interrupt from the keyboard
SIGKILL 9 Kill Signal
SIGTERM 15 Termination signal
SIGSTOP 17, 19, 23 Stop process
Kill processes by ID:
So, let’s use the kill command to terminate our Application. The syntax would be like this:
Send the kill signal to kill 4129 processes:
Send the signal to hang up the 5427 processes:
Send the signal to interrupt the process 5250 from the keyboard:
Kill process by name:
If you want to kill all the processes running in the application. Use killall command:
All the processes running in an application have been killed successfully.
Conclusion:
Before killing any Linux processes, first, we need to see the list of all running processes to get the process ID. We can use multiple signals with the kill command, whereas each signal is used for a specific purpose.