Linux 我可以中止当前正在运行的 bash 命令吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4183665/
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
Can I abort the current running bash command?
提问by Owen
Is it possible to manually abort the currently running bash command? So, for example, I'm using 'find' but it's taking ages... how do I manually stop it?
是否可以手动中止当前正在运行的 bash 命令?因此,例如,我正在使用“查找”,但它需要很长时间......我如何手动停止它?
采纳答案by Chris Morgan
Some things won't respond to Ctrl+C; in that case, you can also do Ctrl+Zwhich stops the process and then kill %1
- or even fg
to go back to it. Read the section in man bash
entitled "JOB CONTROL" for more information. It's very helpful. (If you're not familiar with man
or the man pager
, you can search using /
. man bash
then inside it /JOB CONTROL
Enterwill start searching, nwill find the next match which is the right section.)
有些事情不会响应Ctrl+C;在这种情况下,您还可以执行Ctrl+Zwhich 停止该过程,然后kill %1
- 甚至fg
返回它。man bash
有关更多信息,请阅读标题为“作业控制”的部分。这是非常有帮助的。(如果您不熟悉man
或 man pager
,您可以使用/
.man bash
进行搜索。然后在其中/JOB CONTROL
Enter开始搜索,n将找到下一个匹配项,即正确的部分。)
回答by Ignacio Vazquez-Abrams
Press CtrlCto send SIGINT
to the command to attempt to interrupt it.
按CtrlC发送SIGINT
命令以尝试中断它。
回答by Nicolas
Ok, so this is the order:
好的,这是顺序:
1st try: Ctrl+c
第一次尝试: Ctrl+c
2nd try: Ctrl+z
第二次尝试: Ctrl+z
3rd: login to another console, find the process of the command within your first console that is not responding to both previously mentioned abort/sleep keystrokes with: ps aux
第三:登录到另一个控制台,在你的第一个控制台中找到没有响应前面提到的中止/睡眠按键的命令进程: ps aux
Then kill the process with: kill -9 <PROCESSID>
然后使用以下命令终止进程: kill -9 <PROCESSID>
Of course there may be smarter parameters to the ps command or the possibility to grep , but this would complicate the explanation.
当然, ps 命令可能有更智能的参数或 grep 的可能性,但这会使解释复杂化。