将 SIGINT (Ctrl-C) 发送到在 Eclipse 控制台中运行的程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8814383/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:32:45  来源:igfitidea点击:

Sending SIGINT (Ctrl-C) to program running in Eclipse Console

pythoneclipsetwistedsigint

提问by vsekhar

I have setup a run configuration in Eclipse and need to send SIGINT (Ctrl+C) to the program. There is cleanup code in the program that runs after SIGINT, so pressing Eclipse's "Terminate" buttons won't work (they send SIGKILL I think). Typing CTRL+Cinto the Console also doesn't work.

我在 Eclipse 中设置了一个运行配置,需要向程序发送 SIGINT ( Ctrl+ C)。程序中有在 SIGINT 之后运行的清理代码,因此按下 Eclipse 的“终止”按钮将不起作用(我认为它们会发送 SIGKILL)。在控制台中键入CTRL+C也不起作用。

How do I send SIGINT to a process running inside an Eclipse Console?

如何将 SIGINT 发送到在 Eclipse 控制台内运行的进程?

(FWIW I am running a Twisted daemon and need Twisted to shutdown correctly, which only occurs on SIGINT)

(FWIW 我正在运行一个 Twisted 守护进程,需要 Twisted 才能正确关闭,这仅发生在 SIGINT 上)

回答by jordanm

If you can determine the process with a utility such as ps, you can use kill to send it a SIGINT. The program will likely be a child process of eclipse.

如果您可以使用 ps 等实用程序确定进程,则可以使用 kill 向其发送 SIGINT。该程序可能是eclipse的子进程。

kill -s INT <pid>

回答by John Smithv1

You can send the command via one line:

您可以通过一行发送命令:

 kill -SIGINT $(ps aux | grep ProgrammName | grep -v grep | awk '{print }') 

Get the process id and than send the sigint signal

获取进程 id 然后发送 sigint 信号

回答by Jens Piegsa

That still seems to be an open issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016

这似乎仍然是一个悬而未决的问题:https: //bugs.eclipse.org/bugs/show_bug.cgi?id=38016

Just for the sake of completeness: If you came here to find a way to terminate a read line from System.in, Ctrl+ Zworked for me (on Windows).

只是为了完整起见:如果您来这里是为了找到一种方法来终止从System.in, Ctrl+Z对我来说有效的读取行(在 Windows 上)。

回答by avish

in some versions, you can do the following.

在某些版本中,您可以执行以下操作。

In the Debug perspective, you can open a view called "Signals" (Window/Show View/Signals" or Left-Bottom Icon).

在 Debug 透视图中,您可以打开一个名为“Signals”的视图(Window/Show View/Signals”或 Left-Bottom Icon)。

You will get a list of all supported signals. Right-click and "Resume with Signal" will give you the result you need.

您将获得所有支持信号的列表。右键单击并“使用信号恢复”将为您提供所需的结果。