Everyone must be very familiar with kill -9, and it is often used in work. Especially when you go to restart tomcat. But for the most part, our understanding of -9 is only superficial.
Few people (including me) seriously understand what kill -n is. Criticize yourself.
All right. Let's get to know this familiar stranger well.
1)kill
It can be clearly seen from the help that -n refers to the signal number, so the question is, who is the "signal number"? ? ?
2) kill -l (view Linux/Unix signal variables)
So many! ! Let 's talk about SIGKILL and SIGTERM separately today
3)(kill pid) 、( kill -15 pid)
The system will send a SIGTERM signal to the corresponding program. When the program receives the signal, the following things will happen
- program stops immediately
- Stop when the program releases the corresponding resources
- Program may still continue to run
After most programs receive the SIGTERM signal, they will first release their own resources and then stop. But there are also programs that can do other things after receiving the semaphore, and these things can be
configured. If the program is waiting for IO, it may not respond immediately.
That is to say, SIGTERM is mostly blocked and ignored.
4)kill -9 pid
Can't you not respond to SIGTERM? ? Well, I'll give you the next kill order, I think you're still not obedient. Most admins will use this command
However, not all programs will be obedient, and there are always programs in those states that cannot respond immediately.
appendix:
linux signals
Signal Name | Number | Description |
SIGHUP | 1 | Hangup (POSIX) |
SIGINT | 2 | Terminal interrupt (ANSI) |
SO MUCH | 3 | Terminal quit (POSIX) |
SEAL | 4 | Illegal instruction (ANSI) |
SIGTRAP | 5 | Trace trap (POSIX) |
SIGIOT | 6 | IoT Trap (4.2 BSD) |
SIGBUS | 7 | BUS error (4.2 BSD) |
SIGFPE | 8 | Floating point exception (ANSI) |
SIGKILL | 9 | Kill(can't be caught or ignored) (POSIX) |
SIGUSR1 | 10 | User defined signal 1 (POSIX) |
SIGSEGV | 11 | Invalid memory segment access (ANSI) |
SIGUSR2 | 12 | User defined signal 2 (POSIX) |
SIGPIPE | 13 | Write on a pipe with no reader, Broken pipe (POSIX) |
SIGALRM | 14 | Alarm clock (POSIX) |
SIGTERM | 15 | Termination (ANSI) |
SIGSTKFLT | 16 | Stack fault |
SIGCHLD | 17 | Child process has stopped or exited, changed (POSIX) |
SIGCONT | 18 | Continue executing, if stopped (POSIX) |
SIGSTOP | 19 | Stop executing(can't be caught or ignored) (POSIX) |
SIGTSTP | 20 | Terminal stop signal (POSIX) |
SIGTTIN | 21 | Background process trying to read, from TTY (POSIX) |
SIGTTOU | 22 | Background process trying to write, to TTY (POSIX) |
SIGURG | 23 | Urgent condition on socket (4.2 BSD) |
SIGXCPU | 24 | CPU limit exceeded (4.2 BSD) |
SIGXFSZ | 25 | File size limit exceeded (4.2 BSD) |
SIGVTALRM | 26 | Virtual alarm clock (4.2 BSD) |
SIGPROF | 27 | Profiling alarm clock (4.2 BSD) |
SIGWINCH | 28 | Window size change (4.3 BSD, Sun) |
SIGIO | 29 | I/O now possible (4.2 BSD) |
SIGPWR | 30 | Power failure restart (System V) |
References :
https://major.io/2010/03/18/sigterm-vs-sigkill/
http://blog.csdn.net/ashlingr/article/details/8057825
http://www.comptechdoc.org/os/linux/programming/linux_pgsignals.html