screen (Greg B.)

This is a useful tool for anyone who uses ssh. It allows you to close your terminal and still have processes running. This is very useful if you are using a laptop for example. You can check in on the process from anywhere afterwards.


#Say you want to log into sci-borg
>ssh -t just_greg@zoology.ubc.ca ssh -2 cluster

#start a screen
>screen
# press enter again
# start any process, for example top:
>top

Now, to enter a screen command first press Ctrl+a now the next letter you type will do something with screen. Here are the ones I use:

c # Creates a new screen
n # Next screen
d # Detach

So, to continue our example, you could do “Ctrl+a”, “c” to create a new screen, start R in it and “Ctrl+a”, “n” as many times as you want to toggle between R and top. Once you have your R script running (or what ever you want to do) and you are sure you are not about to crash sci-borg you can do “Ctrl+a”, “d”. Now you are back to where you were before you started the screen.


# exit sci-borg
>exit
# close your terminal on your computer
>exit
# go home have dinner etc. etc... want to check you program?
# open a terminal (on any computer)
>ssh -t just_greg@zoology.ubc.ca ssh -2 cluster

# Re attach, if you dont do the -r you will start another screen!
>screen -r

There are your processes now just use the “Ctrl+a” commands. When you are all done you can kill your screens with “Ctrl+a”, “k” and “y”.

4 thoughts on “screen (Greg B.)

  1. For similar functionality (and a bit easier, in my opinion), you can also use nohup with any command in unix. Simply add ‘nohup’ to the beginning and add & to the end. If the program makes output that would normally be printed to the screen, this can go to a log file, or wherever you want to save it. The default is for that to go to a file called nohup.out, in your working directory. The process will run in the background and will continue to run if you lose your connection or close your terminal. You can check on the processes you have running using ‘ps’. This will tell you all of the processes started from your current terminal. ps has many added things you can do. If I want to check on all of my processes that are running on a machine:
    ps -U nkane
    For the full process details:
    ps -fU nkane | less
    to look at all of the processes that anyone is running that involve structure:
    ps -faux | grep structure | less
    As an example: an extremely useful awk one-line command I used last night to filter a very large table, Fst-W-LE.tab, based on the values in columns 44-47, and output to a new table, hetfiltFst_W-LE.tab, below. Of course, awk is so fast that it can quickly parse this huge file and nohup is not necessary, but I wanted to use this as example because it also illustrates the awesome power of awk, too:
    nohup awk ‘$44 > 10 && $45 > 10 && $47 < 0.1 && $46 > 0.5′ < Fst_W-LE.tab > hetfiltFst_W-LE.tab &

  2. You can also kill a screen while you are in it by typing “Ctrl + a” (there wont be any changes in your window now) followed by “:quit”.

  3. Byobu is an enhancement of Screen that provides useful statistics and hotkeys for the basic commands. I like it much more than using Screen alone. For example, if you type byobu all of your shells that you have opened become visible on the bottom of the window along with information about your system. Generally, the same short cuts that you use in Screen apply with Byobu, but it is more user friendly. Here is a link describing some of its functions http://www.techrepublic.com/blog/opensource/enhance-screen-with-byobus-cool-functionality/2006

Comments are closed.