Perl语言专家Randal Schwartz在一篇短文里这样写:
no no no. 不要使用kill -9.
它没有给进程留下善后的机会:
- 关闭socket链接
- 清理临时文件
- 将自己将要被销毁的消息通知给子进程
- 重置自己的终止状态
......
通常,应该发送15,等一两秒钟,如果没效果,发送2,如果还不行,发送1。如果还不行,那你应该把那个程序删掉,因为那个程序写的太烂了!
不要使用kill -9。不要用收割机来修剪花盆里的花。
总之,在使用kill -9前,你应该先使用kill -15,给目标进程一个清理善后工作的机会。 进程也许无法捕捉或直接忽略SIGKILL信号,但它们可以,通常也是能够捕捉SIGTERM信号的如果你不留机会让进程完成清理工作,它们会留下一些不完整的文件或状态,当系统重启时,程序将无法理解这些状态。
|Signal Name | Number | Description
|-
|SIGHUP | 1 | Hangup (POSIX)
|SIGINT | 2 | Terminal interrupt (ANSI)
|SIGQUIT | 3 | Terminal quit (POSIX)
|SIGILL | 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)
原文地址:http://unix.stackexchange.com/questions/8916/when-should-i-not-kill-9-a-process