Reputation: 45491
It seems that in Eclipse, if you want to send ctrl+c to a process you cant. The terminate button on the console just kills the running process without running the shutdown hooks. I know that java itself doesnt allow sending a signal to another process.
However it seems that intellij idea does have a 'exit' button next to its 'stop' button which does allow shutdown hooks to run.
Can somebody tell me how intellij does this?
I need to send ctrl+c from my program to another java process too.
Upvotes: 29
Views: 15169
Reputation: 635
Intellij use a native library to send a signal on Windows and the command kill on Unix.
Here is a source code
Has you said you can't send a signal in Java. So you need to execute native code.
Look at the question here
Upvotes: 4
Reputation: 5151
It is my understanding that this happens only on Windows with Eclipse. Also see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016
As far as just testing your hooks you can do it by calling System.exit() and then I suppose your users will not run the application using Eclipse so it's ok to count on it working for them.
Upvotes: 1