Table of Contents
Useful links and sources
Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.
Each virtual terminal provides the same functions of the usual terminal. There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows.
When screen is called, it creates a single window with a shell and the gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scrollback history, etc. All windows run their programs completely independent of each other. Screen allows programs to continue to run when the window is currently not visible and even when the whole screen session is detached from the user's terminal.
When a program terminates, screen (per default) kills the window that contained it. If this window was in the foreground, the display switches to the previously displayed window; if none are left, screen exits.
Create/Re-attach Screen Session
Create a screen with the parameters x and R
$ screen -xR
-x will attach to a not detached screen, for multi display mode.
-R wil resume the last detached screen session. If one doesn't exist, it will start a new session.
For more command parameters use
$ screen -help
While in the screen, you can press CTRL + a, then ? to view all available commands
Leaving Screen Session
Detaching the page will allow you to leave the session without quitting the process
press CTRL + a, then d
Killing a screen will also kill any process it is running
press CTRL + a, then k
Open an SSH connection and remember the host you are on
$ hostname ramon-limon
Create a new screen instance
$ screen -xR
Create a bash script to run a job in the background, below is a script that will print every 10 seconds, 100 times.
$ vim test.sh
#!/bin/bash echo `hostname` COUNT=0 while [ $COUNT -lt 100 ]; do let COUNT=COUNT+1 echo COUNT $COUNT sleep 10 done
Open permissions on the .sh file
$ chmod 755 test.sh
Execute the script
You should see the script running, now to test wether it continues after exit. Again, please remember the hostname of the system you are running the job on. To exit the screen, press ctrl-a, then press d. You can re-enter the screen by again running the command
$ screen -xR
Now try closing out the shell and reconnecting to the host at [whatever hostname].ics.uci.edu. If you run the screen command again, you will find that your process is still running!
Tips for large jobs
- Remember the hostname
- Don't have it running endlessly, have some sort of time constraint.
- Get updates on the job's progress. This can be done with email, logs, etc.