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?

Robert
  • 507
  • 2
  • 9
  • 20

1 Answers1

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.
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • Thanks! Waht i should use to run shutdown hook on windows, from my C# application? – Robert Jul 03 '12 at 13:27
  • How can i send CTRL-C signal to java application – Robert Jul 03 '12 at 13:30
  • I would suggest rather trying to kill the process using cmd? I cannot however say for sure it will work, see here for more: http://techmonks.net/windowsxp-using-the-command-prompt-to-see-and-kill-processes/ you'll have to test it, Though a draw back would be your jar's portability. – David Kroukamp Jul 03 '12 at 13:30
  • @Robert this might help for sending the CTRL-C to your Java console: http://stackoverflow.com/questions/2517586/c-send-ctrlc-to-console-program-started-with-process-start see the answers link – David Kroukamp Jul 03 '12 at 13:31