How to do something before process get killed in windows

前端 未结 3 2005
清酒与你
清酒与你 2021-01-14 14:26

My program need to occupy some resources. I want it to release those resources before exit. It\'s easy to achieve when the excutable exit normally. However, what if the user

3条回答
  •  误落风尘
    2021-01-14 15:02

    It seems impossible to react to the process being killed. The way to do that would be to use signals but as the doc says (here), the SIGTERM signal is not generated under windows NT.

    You could try to PInkoke the signal function and catch SIGINT if your program is a console application and you want to react to ctrl+c.

    Like others said, Windows will free up resources for you and the only that is dangerous is that your open files will be left in an unknown state, so it might not be worth the effort.

提交回复
热议问题