Guys sorry if I have offended someone by asking such a noob question, as I see someone have "Marked Down" Question for being inappropriate.
This is my first time asking here so forgive me if something isn't appropriate, and sorry if my English isn't very good.
I'm trying to create a temp file when my program had been closed via the task manager ... but i have no idea about how to detect if my program is closed via the task manager !!!
How do I do that? I googled a lot, but either I used the wrong keywords or there are no simple solutions on the internet. I hope somebody here can help me.
Best regards and thanks in advance.
To catch regular terminate requests like SIGTERM
or WM_CLOSE
, as sent via the taskmanager's 'Applications' tab, a shutdown hook can be installed (I assume, you're using Windows, but that doesn't make much of a difference).
However, when killing from the 'processes' tab, or with taskkill /f ...
on Windows or kill -9 ...
on Linux or Unix, the process (VM) gets forcibly terminated, unable react. The same goes for kills done via 'application not responding' dialogs on Windows.
So you need to make sure, that you can handle files, which are corrupted/incomplete as a result of a forced kill (apart from power outages or hardware failures).
来源:https://stackoverflow.com/questions/20054471/how-to-detect-program-java-force-to-close-from-windows-task-manager