Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect program java force to close from Windows Task Manager?

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.

like image 420
Ahmad MOUSSA Avatar asked Nov 18 '13 17:11

Ahmad MOUSSA


People also ask

How do I stop a java process in Windows?

If you want to kill all java.exe processes : taskkill /F /IM java.exe /T .

How do I find out what java process is running on Windows?

Find the full command line of your java application Say hello to Windows Task Manager. Go to 'Processes' tab. You will see the list of processes running on the system.

How do I know if java program is running?

If you want to check the work of java application, run 'ps' command with '-ef' options, that will show you not only the command, time and PID of all the running processes, but also the full listing, which contains necessary information about the file that is being executed and program parameters.


1 Answers

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).

  • Signal handling using "TERM"
  • Really killing a process in Windows
like image 150
Sam Avatar answered Oct 17 '22 15:10

Sam