Wednesday, 17 March 2010

Interrupting R processes in Ubuntu

It's funny how things happen. Yesterday I was working away on a project in R and the unenjoyable happens---the process hangs for longer than desired. I operate R in the standard GNOME terminal in Ubuntu and the only way I knew was to close the entire application getting rid of all objects at the same time. Not cool. Thirty minutes or more of fruitless searching gave no indication as to a better way of doing things and I was really wishing the ESC key worked as it does in Windows.

Checking emails this morning though, and I discover an exchange on R-help that goes through exactly what I needed to know... From these emails then I have discovered that:
  • Pressing Ctrl+C should work in the terminal.
  • If that doesn't work, open another terminal console and type
    ps aux | grep R

    kill -s INT PID
  • The first line allows you to discover the PID number of your particular R instance, which is then used in the second line.
  • In the second line above, INT may be replaced by HUP in some cases.
  • The above methods set up an alert-thing to tell the program to stop. When the computations are done externally of R, it can't be executed before the external codes checks back with R. If the external code doesn't do this regularly or at all, killing the entire program is the only way out. If none of the above work, this is probably what has happened and it may be a good idea to let the package author know about the problem...
Thanks to all involved in this exchange: Adam Kramer, Duncan Murdoch, Simon Urbanek, Matthew Keller and Ted Harding

2 comments:

vinhdizzo said...

I'd like to point out that the terminal related commands will work on any Linux machine, not just Ubuntu. Moreover, any *nix based machine will have some variant to ps aux.

Samuel Brown said...

Thanks for that Vinhdizzo!