从控制台“退出”(ctrl+c)进程 - Eclipse 与 Intellij
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/868412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Exiting' (ctrl+c) a process from console - Eclipse vs Intellij
提问by pdeva
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 的“停止”按钮旁边似乎确实有一个“退出”按钮,它允许关闭挂钩运行。
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 进程。
回答by mki
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发送信号。所以你需要执行本机代码。
看这里的问题
回答by Alex Florescu
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 运行应用程序,所以可以指望它为他们工作。