As others have pointed out, there is no way you can execute any code in your application when it is being Killed
by Operating System
or User
. That is why its called Killing
.
If saving the state is an important part of your application, you should take an approach similar to a database system. Implementing transaction log
, creating checkpoints
, etc. That is the closest you can get.
In that case, when your application revives (is re-run after being killed
), it can check these transaction logs
for any pending updates or last state changes.
Other than that, it really depends on what you want to do. And also why you came up with this idea? Can we get more details? May be someone here has better alternative.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…