Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop a running R command in linux other than with Ctrl + C?

Tags:

linux

command

r

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?

I don't want to kill the R session to start over either.

like image 218
danioyuan Avatar asked Feb 18 '12 01:02

danioyuan


People also ask

How do I stop the R command from running?

If you're using R from the command line instead of from within RStudio, you need to use Ctrl + C instead of Esc to cancel the command.

How do I stop a run command in Linux?

Hold the Ctrl button and press the C key at the same time. It sends the SIGKILL signal to the running program to force quit the command.


2 Answers

I have had the problem you mention. Ctrl + C will 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?".

Try Ctrl + C first, 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.

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.

like image 103
Xu Wang Avatar answered Oct 13 '22 19:10

Xu Wang


Try to use Ctrl + C, pause R with Ctrl + Z, and then unpause R with 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.

I'm not sure whether it was one of the signals or Ctrl + C that stopped R, but I guess Ctrl + Z was essential here.

like image 34
Oberyn Avatar answered Oct 13 '22 19:10

Oberyn