除了使用 Ctrl + C 之外,如何在 Linux 中停止正在运行的 R 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9337825/
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
How can I stop a running R command in linux other than with Ctrl + C?
提问by danioyuan
I'm running R in interactive mode under Linux and mistakenly typed in a command that takes forever to run. I usually stop it using Ctrl+ C. But it doesn't work all the time. When it doesn't work, is there another way?
我在 Linux 下以交互模式运行 R 并错误地输入了一个需要永远运行的命令。我通常使用Ctrl+停止它C。但它并不总是有效。当它不起作用时,还有其他方法吗?
I don't want to kill the R session to start over either.
我也不想终止 R 会话以重新开始。
回答by Xu Wang
I have had the problem you mention. Ctrl+ Cwill work when R is able to realize "Oh, this guy/gal wants me to stop running that particular command." However, often R cannot do that. So you have to run Ctrl+ \(note that it's a backslash, not a forward slash). This tells Linux "Hey, R is not listening to me, can you stop running R?".
我遇到了你提到的问题。Ctrl+C当 R 能够意识到“哦,这个家伙/gal 希望我停止运行那个特定命令时”会起作用。然而,R 通常无法做到这一点。所以你必须运行Ctrl+ \(注意它是一个反斜杠,而不是一个正斜杠)。这告诉 Linux “嘿,R 没有听我说话,你能停止运行 R 吗?”。
Try Ctrl+ Cfirst, because if it works you will still have your R session. If it doesn't work, and you do Ctrl+ \you will lose your R session, but at least it stops the process.
首先尝试Ctrl+ C,因为如果它有效,您仍将拥有 R 会话。如果它不起作用,并且您这样做了Ctrl+\您将丢失 R 会话,但至少它会停止该过程。
If that doesn't work either, then I would suggest a killall R
or a kill -9 [PID]
where you find the PID by running pus aux
.
如果这也不起作用,那么我建议您通过运行akillall R
或 a 来kill -9 [PID]
找到 PID pus aux
。
回答by Mike
You can also try
你也可以试试
kill -USR1 [pid]
This will interrupt some R calls and sometimes give you the option to save and quit rather killing the process altogether.
这会中断一些 R 调用,有时会为您提供保存和退出的选项,而不是完全终止进程。
回答by Oberyn
Try to use Ctrl+ C, pause R with Ctrl+ Z, and then unpause R with fg
(#job).
尝试使用Ctrl+ C,暂停R 2与Ctrl+ Z,并用然后取消暂停- [R fg
(#job)。
I tried the solutions given in previous answers with sending some signals to R with kill, but neither worked. Then I tried the sequence above (Ctrl+ C, Ctrl+ Z, and fg 1
) and it worked. I could continue the R session.
我尝试了以前的答案中给出的解决方案,通过 kill 向 R 发送一些信号,但都没有奏效。然后我尝试了上面的序列(Ctrl+ C、Ctrl+Z和fg 1
)并且它起作用了。我可以继续 R 会话。
I'm not sure whether it was one of the signals or Ctrl+ Cthat stopped R, but I guess Ctrl+ Zwas essential here.
我不确定是停止 R的信号之一还是Ctrl+ C,但我想Ctrl+Z在这里是必不可少的。
回答by xdeepakv
Ctrl+ Cis not working. Somehow Ctrl+ \will stop the process.
Ctrl+C不工作。不知何故Ctrl+\将停止该过程。
But there is a function in R programming to quit. You can try q()on REPL. It worked for me.
但是R编程中有一个函数可以退出。您可以在 REPL 上尝试q()。它对我有用。
q()