“退出” (ctrl+c) 来自控制台的进程 - Eclipse 与 Intellij

发布于 2024-07-20 12:56:06 字数 247 浏览 4 评论 0原文

似乎在 Eclipse 中,如果您想将 ctrl+c 发送到进程,则不能。 控制台上的终止按钮只是终止正在运行的进程,而不运行关闭挂钩。 我知道java本身不允许向另一个进程发送信号。

然而,intellij idea 的“停止”按钮旁边似乎确实有一个“退出”按钮,它允许关闭挂钩运行。

有人能告诉我 intellij 是如何做到这一点的吗?

我也需要将 ctrl+c 从我的程序发送到另一个 java 进程。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你列表最软的妹 2024-07-27 12:56:06

Intellij 使用本机库在 Windows 上发送信号,并在 Unix 上使用 Kill 命令。
这里有源代码

你有没有说过Java中不能发送信号。 所以你需要执行本机代码。
看看这里的问题

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

帅的被狗咬 2024-07-27 12:56:06

据我了解,这种情况只发生在带有 Eclipse 的 Windows 上。
另请参阅:https://bugs.eclipse.org/bugs/show_bug.cgi ?id=38016

至于只是测试你的钩子,你可以通过调用 System.exit() 来完成,然后我想你的用户不会使用 Eclipse 运行该应用程序,所以可以指望它为他们工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文