1

I have java application which shutdowns correctly when i use CTRL-C, java application saves all data before shutdown. Now i trying to shutdown this java application from my C# console application using Process.Close(), but application dont't save any data when i use this, i also tried Process.CloseMainWindow() but using this nothing is happening, and also Process.Kill() but using this process just killed, without any savining.

How can i raise shutdown hook on java application from C# console application?

3
  • do you already have a shutdown hook in your app and Process.close() does not trigger it? Commented Jul 3, 2012 at 12:13
  • ok, sorry, didn't read the question carefully Commented Jul 3, 2012 at 12:17
  • is your shutdown hook executed when you end the program from task manager? if so, you can try posting WM_QUIT or WM_CLOSE messages to your java process. Commented Jul 3, 2012 at 16:31

1 Answer 1

2

A shutdown hook cannot be raised by another app.

The shutdown hook runs when:

  • A program exists normally. For example, System.exit() is called, or the last non-daemon thread exits.
  • the Virtual Machine is terminated. e.g. CTRL-C. This corresponds to kill -SIGTERM pid or kill -15 pid on Unix systems.

The shutdown hook will not run when:

  • the Virtual Machine aborts
  • A SIGKILL signal is sent to the Virtual Machine process on Unix systems. e.g. kill -SIGKILL pid or kill -9 pid
  • A TerminateProcess call is sent to the process on Windows systems.
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! Waht i should use to run shutdown hook on windows, from my C# application?
How can i send CTRL-C signal to java application
I would suggest rather trying to kill the process using cmd? I cannot however say for sure it will work, see here for more: techmonks.net/… you'll have to test it, Though a draw back would be your jar's portability.
@Robert this might help for sending the CTRL-C to your Java console: stackoverflow.com/questions/2517586/… see the answers link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.