views:

927

answers:

3

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.

+1  A: 

It was my understanding that the Ctrl+C is a KILL signal which skips all kinds of signal handling and just terminates the program, NOW. Are you sure that Intellij is not simply using a "weaker" signal for ending the program, similar to SIGINT in linux?

Stefan Thyberg
well the question is how does intellij send any signal at all since java doesnt support sending signals.
pdeva
Well, another problem with your question is that you do not say which OS this concerns, process handling is not something that's very similar between operating systems.
Stefan Thyberg
since its java, its really a multiplatform problem for me
pdeva
A: 

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.

anothem
A: 

Windows? Run eclipse using the eclipsec.exe program and then you'll have an extra console window that you can issue the CTRL-C to.

Mark O'Connor