Spring Boot在Sigkill上清理

时间:2018-10-03 08:46:39

标签: spring-boot predestroy

我正在运行一个SpringBoot应用程序。我使用@PreDestroy批注添加了一些清理操作。当我使用杀死Tomcat的$ {PID}的SIGTERM终止进程时,它将通过调用标有@PreDestroy的方法来执行所有清理任务。但是,当我使用SIGKILL即杀死tomcat的-9 $ {PID}时,不会执行清理。

使用SIGKILL终止应用程序时,有什么方法可以使应用程序执行所有销毁工作?

1 个答案:

答案 0 :(得分:0)

不,没有。常规kill等待进程退出,而kill -9不退出并立即终止进程。重要的是,不能捕获,阻止或忽略信号SIGKILL和SIGSTOP。 man 7 signal简要概述了每种信号的含义:

   Signal     Value     Action   Comment
   ──────────────────────────────────────────────────────────────────────
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
   SIGINT        2       Term    Interrupt from keyboard
   SIGQUIT       3       Core    Quit from keyboard
   SIGILL        4       Core    Illegal Instruction
   SIGABRT       6       Core    Abort signal from abort(3)
   SIGFPE        8       Core    Floating-point exception
   SIGKILL       9       Term    Kill signal
   SIGSEGV      11       Core    Invalid memory reference
   SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                 readers; see pipe(7)
   SIGALRM      14       Term    Timer signal from alarm(2)
   SIGTERM      15       Term    Termination signal
   SIGUSR1   30,10,16    Term    User-defined signal 1
   SIGUSR2   31,12,17    Term    User-defined signal 2
   SIGCHLD   20,17,18    Ign     Child stopped or terminated
   SIGCONT   19,18,25    Cont    Continue if stopped
   SIGSTOP   17,19,23    Stop    Stop process
   SIGTSTP   18,20,24    Stop    Stop typed at terminal
   SIGTTIN   21,21,26    Stop    Terminal input for background process
   SIGTTOU   22,22,27    Stop    Terminal output for background process