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.
似乎在Eclipse中,如果你想将ctrl + c发送给你不能进行的进程。控制台上的终止按钮只会在不运行关闭挂钩的情况下终止正在运行的进程。我知道java本身不允许向另一个进程发送信号。
However it seems that intellij idea does have a 'exit' button next to its 'stop' button which does allow shutdown hooks to run.
然而,似乎intellij idea的'stop'按钮旁边有一个'exit'按钮,它允许关闭钩子运行。
Can somebody tell me how intellij does this?
谁能告诉我intellij怎么做?
I need to send ctrl+c from my program to another java process too.
我需要从程序中将ctrl + c发送到另一个java进程。
2 个解决方案
#1
Intellij use a native library to send a signal on Windows and the command kill on Unix.
Here is a source code
Intellij使用本机库在Windows上发送信号,在Unix上发送命令kill。这是源代码
Has you said you can't send a signal in Java. So you need to execute native code.
Look at the question here
你说过你不能用Java发送信号吗?所以你需要执行本机代码。看看这里的问题
#2
It is my understanding that this happens only on Windows with Eclipse. Also see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016
据我所知,这只发生在使用Eclipse的Windows上。另见: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.
至于只是测试你的钩子你可以通过调用System.exit()来做到这一点,然后我想你的用户不会使用Eclipse运行应用程序,所以可以依靠它为它们工作。
#1
Intellij use a native library to send a signal on Windows and the command kill on Unix.
Here is a source code
Intellij使用本机库在Windows上发送信号,在Unix上发送命令kill。这是源代码
Has you said you can't send a signal in Java. So you need to execute native code.
Look at the question here
你说过你不能用Java发送信号吗?所以你需要执行本机代码。看看这里的问题
#2
It is my understanding that this happens only on Windows with Eclipse. Also see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016
据我所知,这只发生在使用Eclipse的Windows上。另见: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.
至于只是测试你的钩子你可以通过调用System.exit()来做到这一点,然后我想你的用户不会使用Eclipse运行应用程序,所以可以依靠它为它们工作。