Run long computations remotely with screen

This post assumes you use UNIX-like operating system on your computer.

At some point I needed to run some extensive computations on a remote computer from my laptop. The problem was that this would take a long time and I would like to log out from the remote terminal and only log in later to see if the results were ready. If that is also your problem, then screen is the software for you.

screen is useful to detach and reattach your terminals and to have multiple terminals when you’re logged in remotely.

If you don’t have it installed type:

sudo apt-get install screen

Log in to the remote account and start screen.

screen # start screen
R # Run something, e.g. R statistical software.
<Ctrl+a c> # That creates a new screen terminal.
R # Run another thing, R again in this case.
<Ctrl+a d> # That detaches screen from your session and sends it into the background.

Now that you have detached your screens you can log out, go to another computer and log in again.

screen -r # your screen terminals will be reattached.

You can press <Ctrl+a n> or <Ctrl+a p> to cycle through your terminals. Type exit to terminate this screen session including all its terminals.

To scroll up and down you need to be in copy mode first, press <Ctrl+a [> to enter in copy mode and Esc to exit copy mode.


2 thoughts on “Run long computations remotely with screen

  1. Hey Thiago, I was wondering if you have tried to use tmux?

    By the way, I just ran across you blog today and I really like it.

    • Hi Craig,

      Thanks for reading. I have never tried tmux. I just looked it up and wonder if you can give me an example where it would be better than ‘screen’ or what does it do that ‘screen’ does not.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s