Linux Command kill
Proficient in Linux kill commands
No matter which operating system you use, you will surely encounter an abnormal application that locks itself and refuses to close it. In Linux (and Mac), you can use a "kill" command to force it to end. In this tutorial, we will show you how to use the "kill" command to end the application.
Kill command and Signal
When you execute a "kill" command, you actually send a signal to the system to end abnormal applications. There are a total of 60 signals you can use, but basically you only need to know SIGTERM (15) and SIGKILL (9 ).
You can use this command to view the list of all signals:
Kill-l
• SIGTERM-this signal requests a process to stop running. This signal can be ignored. A process can be shut down normally for a period of time. It usually takes some time to save the progress and release resources. In other words, it is not forced to stop.
• SIGKILL-this signal forces the process to stop running immediately. The program cannot ignore this signal, but the unsaved progress will be lost.
The syntax for "kill" is:
Kill [signal or option] PID (s)
The default signal (when not specified) is SIGTERM. When it does not work, you can use the following command to force kill a process:
Kill SIGKILL PID
Or
Kill-9 PID
Here "-9" represents the SIGKILL signal.
If you do not know the PID of the application, run the following command:
Ps ux | grep firefox
It displays the PID of all running applications and applications.
For example, to kill Chrome, I will run the following command:
Kill-9 3629
You can kill multiple processes at the same time.
Kill-9 PID1 PID2 PID3
PKill
The "pkill" command allows the use of extended regular expressions and other matching methods. You can kill the application process name instead of the PID. For example, to kill the Firefox browser, you only need to run the following command:
Pkill firefox
If you use a regular expression to match, you can enter some characters of the process name, such:
Pkill fire
To avoid kill the wrong process, you should use the "pgrep-l [process name]" list to match the process name.
Killall
Killall also uses the process name to replace the PID, and it will kill all processes with the same name. For example, if you are running multiple Firefox browser instances, run the following command to kill them all:
Killall firefox
In Gnome, you can use this command to restart Nautilus:
Killall nautilus
Xkill
Xkill is a graphical method to kill an application. When you type "xkill" on the terminal, your cursor will immediately become a "Cross ". You only need to click on an abnormal application, and it will kill the application immediately. If you often use it, you can also add a keyboard shortcut to activate xkill.
Conclusion
When the system is suspended due to abnormal applications, people often restart the computer and start all the tasks again. With these "kill" commands, you can better handle abnormal applications and avoid system crashes. It is especially useful when you don't want to cause server downtime because of an abnormal process.
--------------------------------
Dylan Presents.