Linux KILL command

Source: Internet
Author: User

purpose of the KILL command

The KILL command is easy to misunderstand, believing that it is only used to kill the process. Let's take a look at the man page's explanation for it: kill-send a signal to a process.

From the official explanation it is not difficult to see that kill is the command that sends a signal to the process. Of course we can send a signal to the process to terminate the operation, at which time the kill command is named to the real. In fact, if we don't pass the signal parameter to the KILL command, it defaults to passing the signal to the process to terminate the process! This is the most important use of the kill command and is what this article describes.

In general, terminating a foreground process using Ctrl + C is possible. The KILL command is required for a background process to terminate. We will first use the PS, top and other commands to get the PID of the process, and then use the KILL command to kill the process.

KILL command Format
Kill [Options] <pid> [...] <pid> [...]: Sends the signal to all the processes listed.
Options:
-<signal> : Specifies the signal sent to the process, specifying the name or number of the signal. -L: Lists the names and numbers of all the signals.
kill command DetailsView available Signals

Now that the KILL command is used to send signals to the process, let's start by looking at what signals can be sent to the process.

Kill -L

But a lot! However, only the 9th signal (SIGKILL) can terminate the process unconditionally, other signal processes have the right to ignore. And so many of the signals used are not much, below we explain the meaning of a few common signals.

Code
Name Content
1
SIGHUP Starts a program that is terminated, allowing the process to reread its own configuration file, similar to restarting.
2 SIGINT Equivalent to using the keyboard input [ctrl]-c to interrupt a program.
9 SIGKILL The representative forces the interruption of a program, and if the program is halfway through, then the unfinished part may have a "half product", similar to what Vim would have. Filename.swp.
15 SIGTERM Terminate the program in a normal manner. Because it is normal to terminate, the subsequent action will be done by him. However, if the program already has a problem, it is not possible to use the normal method of termination, the input of this signal is also useless.
19 SIGSTOP Equivalent to using the keyboard input [ctrl]-z to pause a program.

The above table is only a common signal, more signal information please self through the man 7 signal understand. In general, just remember the meaning of the three signals "1, 9, 15".

Common Commands
kill - pid

This command sends a signal that the process exits normally. The so-called normal exit refers to the exit process completed by the application's own exit, so that resources can be cleaned and freed. For example, VIM program, if it is normal exit, it will delete the temporary file *.SWP.
Since signal 15 is the correct way to exit the process, it should also be the most common way, so we can omit the parameter-15.

kill PID

This command is equivalent to the above command, and the KILL command sends the signal 15 to the target process by default.

When the process has an abnormal condition and cannot exit normally via signal 15, we need to terminate the process directly by means of a very good method. The so-called very means is to pass the signal 9 to the target process!

Kill -9 PID

This end-of-process does not clean up the resource, so if you use it to end the VIM process, you will find that the temporary file *.swp has not been deleted.

Summary

The use of signal 15 is safe, and signal 9 is the last resort to handle abnormal processes, do not misuse.

Linux KILL command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.