Introduction:
No matter which operating system you use, you are bound to encounter an application that behaves erratically, locking itself down and refusing to shut it down. In Linux (and Mac), you can force the end of it with a kill command. In this tutorial, we'll show you a variety of ways to use the KILL command to end an application.
Kill command
1,kill Command and Signal:
When you execute a KILL command, you actually send a signal to the system to end an abnormal application. There are a total of 60 signals you can use, but basically you just need to know Sigterm (15) and Sigkill (9).
The KILL command works by sending a system action signal to the kernel of the Linux system and a process identification number for a program, and the system kernel can then operate on the process specified by the process identification number. For example, in the top command, we see that the system runs many processes, and sometimes it is necessary to abort certain processes using kill to improve system resources. Kill is a direct call to most shell internal commands.
2, you can use this command to see a list of all the signals, which lists all the signal names:
$ kill-l
Sigterm: This signal requests a process to stop running. This signal can be ignored. Processes can be shut down for a period of time, and the normal shutdown of a program typically takes a while to save 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, and the unsaved progress will be lost.
3, the syntax for using "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 the kill of a process:
Kill SIGKILL PID
Or
Kill-9 PID
Here "-9" represents the Sigkill signal.
For example, to kill Chrome, I'll run the command:
Kill-9 3629, through $ ps-aux can get PID
You can also kill multiple processes at the same time.
Kill-9 PID1 PID2 PID3
Gets the value of the specified signal
[Root@localhost test6]# kill-l Kill
9
[Root@localhost test6]# kill-l SIGKILL
9
[Root@localhost test6]# kill-l TERM
15
[Root@localhost test6]# kill-l Sigterm
15
The 4,init process is not to be killed.
Command: kill-9 1
Init is one of the most indispensable programs in Linux system operations. The so-called init process, which is a user-level process initiated by the kernel. After the kernel starts itself (has been loaded into memory, starts running, and has initialized all device drivers and data structures, etc.), it completes the boot process by starting a user-level program init. Therefore, Init is always the first process (its process number is always 1). All other processes are descendants of the INIT process. The init process is not to be killed.
killall command: Killall also uses the process name instead of PID, and it will kill all processes with the same name. For example, if you are running instances of multiple Firefox browsers, you can kill them all by command:
Killall Chrome
xkill Command:
Xkill is a graphical way to kill an application. When you type "Xkill" in the terminal, your cursor will immediately become a "cross". All you have to do is click on an abnormal application and it will kill the application immediately.
Attention:
$ kill-9 PID, this powerful and dangerous command forces the process to terminate abruptly at run time, and the process cannot clean itself after the end. The hazard is that the system resources are not released normally and are not recommended unless otherwise available.
When using this command, be sure to confirm with ps-ef that there are no zombie processes left. Zombie processes can only be eliminated by terminating the parent process. If the zombie process is adopted by INIT, the problem is more serious. Killing the init process means shutting down the system.
If there is a zombie process in the system, and its parent process is init, and the zombie process consumes a large amount of system resources, it is necessary to reboot the machine at some point to clear the process table.
The standard KILL command usually achieves the purpose. Terminate the problematic process and release the resources of the process to the system. However, if a process starts a child process and kills only the parent process, the child process is still running and therefore consumes resources. To prevent these so-called "zombie processes", be sure to kill all of their child processes before killing the parent process.