How to Stop a Running R Command in Linux Other Than with Ctrl + C

How to terminate R from terminal?

Finally, found a workaround from my colleague.

cd .rstudio/
rm -r sessions #this will delete the .RData file from session workspace
sudo rstudio-server restart

Stop running script but not programm it started

just add & at the end of the line.

also in the terminal you can do the same. but if you close it the process you started is killed even if you add & ,so you have to disown the process by adding & disown ,which you don't need in the script.

Stop submitted lines of code from running

Assuming you're running in console (or interactive session in R studio, that's undetermined from your question) and that what you did was sourcing a script/pasting code and while it was running pasting another chunck of code:

What is ongoing is that you pushed data into R process input stream, it's a buffered input, so it will run each line once the previous line call has ended and free the process.

There's no easy way to play with an input buffer, that's R internal input/output system and mostly it's the Operating system which have those information in cache for now.

Asking R itself is not possible as it already has this buffer to read, any new command would go after.

Last chance thing: If you can spot your another chunck of code starting in your console, you can try pressing the esc key to stop the code running.

You may try messing with the process buffers with procexp but there's a fair chance to just make your R session segfault anyway.

To avoid that in the future, use scripts and run them on the command line separately with Rscript (present in R bin directory under windows too despite the link pointing to a linux manpage).

This would create one session per script and allow to kill them independently. That said if they both write to the same place (database, a file would create an error if accessed by two process) that won't prevent data corruption.

How can we prevent CTRL-C from screen terminating?

Each of your screen instances is created to run a single command, start.sh. When this command terminates, for instance when you interrupt it, the screen will have done its job and terminate. The reason for this is that screen runs shell scripts directly in a non-interactive shell, rather than spawning a new interactive shell and running it there.
If you wanted to run start.sh inside an interactive shell in each screen, you'd do something like this:

screen -dmS "$name" /bin/bash -i
screen -S "$name" -X stuff "./start.sh^M"

The ^M is needed as it simulates pressing enter in your shell within screen.

If you use this, then when you interrupt a script within screen, you will still be left with an interactive prompt afterward to deal with as you see fit.



Related Topics



Leave a reply



Submit