How to gracefully handle the SIGKILL signal in Java

前端 未结 5 2105
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 11:34

How do you handle clean up when the program receives a kill signal?

For instance, there is an application I connect to that wants any third party app (my app) to se

5条回答
  •  故里飘歌
    2020-11-22 11:51

    There is one way to react to a kill -9: that is to have a separate process that monitors the process being killed and cleans up after it if necessary. This would probably involve IPC and would be quite a bit of work, and you can still override it by killing both processes at the same time. I assume it will not be worth the trouble in most cases.

    Whoever kills a process with -9 should theoretically know what he/she is doing and that it may leave things in an inconsistent state.

提交回复
热议问题