When uses log onto remote severs as they do with the MIND cluster, often there are instances where they would like to logoff but still maintain running processes. The use of the following tools will allows users to maintain their sessions ( collections of windows ) and processes after they disconnect from the cluster.
Screen and tmux
Screen and tmux tools works on UNIX based operating systems such as Linux and MacOS. They allow users to use multiple windows and provides a way for a user to detach from a terminal session and then reattach to it at a later time. To be able to do this, the user has to be in a screen or tmux session. ( Just using the terminal won’t allow you do this.) Whenever you are detached from the terminal session, the processes are killed but these tools allow the processes to continue when detached. You can reattach to the particular session at a later time and your active terminals will be as you left them.
To start screen, type screen at the command prompt. Your original session will be detached and you will be brought to a new window.
This shows details such as screen geometry and character set. The important part is that 2(bash) at the end. The 2 is the number of the currently displayed terminal window, and bash is the shell. Users can press crtl+A, then the number of the screen to which they wish to attach, or press Ctrl+A followed by a D to get a list of terminal windows available.
Each screen can run any program contained on the cluster.
To detach a screen and come back to it later…use the system above to start a window with Matlab or another program. Then issue the key Ctrl+A followed by a D. This will drop the user back to the bash prompt after detaching any session. The user may logout at this point.
To reattach an existing session, login to the command prompt and type screen -ls. This will list all detached sessions.
[dpane@psych-o ~]$ screen -ls There is a screen on: 8673.pts-6.psych-o (Detached) 1 Socket in /var/run/screen/S-dpane.
To reattach to that one session, I would type this at the bash prompt:
[dpane@psych-o ~]$ screen -r 8673.pts-6.psych-o
From there, it will return the session to the current login.
Screen Cheat Sheet
- ctrl a c -> create new window
- ctrl a A -> set window name
- ctrl a w -> show all window
- ctrl a 1|2|3|… -> switch to window n
- ctrl a ” -> choose window
- ctrl a ctrl a -> switch between window
- ctrl a d -> detach window
- ctrl a ? -> help
- ctrl a [ -> start copy, move cursor to the copy location, press ENTER, select the chars, press ENTER to copy the selected characters to the buffer
- ctrl a ] -> paste from buffer
- screen –DR -> list of detached screen
- screen –r PID -> attach detached screen session
- screen –dmS MySession -> start a detached screen session
- screen –r MySession -> attach screen session with name MySession
- ctrl a S -> create split screen
- ctrl a TAB -> switch between split screens
- ctrl a Q -> Kill all regions but the current one.
- ctrl a X -> remove active window from split screen
- ctrl a O -> logout active window (disable output)
- ctrl a I -> login active window (enable output)