tmux
tmux is a useful package for keeping computation alive on servers.
If you are performing long-running computations on Linux servers, such as the servers managed by Drexel CCI or my research group’s servers, tmux (or the older screen) is an indispensable program.
tmux is a terminal multiplexer that provides several useful features on top of a standard terminal session, such as an ssh connection to a remote server.
Detaching
The first and most useful of these features is the ability to detach from your session, leaving the programs running, and re-attach later. You can start a job, close your laptop, go home or to a coffee shop or whatever, log back in to the server, and check in on your job. If you run a long-running program in an SSH connection and then your computer disconnects, the program will usually terminate rather unceremoniously.
To use this feature, run tmux to start a new session. To detach, enter Ctrl+b followed by d (abbreviated in Emacs notation as C-b d). Later, you can re-connect to that session with tmux attach. The C-b (Ctrl+b) shortcut is the leader, and all tmux shortcut keys begin with that shortcut (other shortcut keys are passed directly to the program you are running)
Other Features
tmux has several other useful features as well, including:
- Multiple windows, allowing you to have several different terminal sessions over the same SSH connection, and re-attach to the whole set (like tabs in your terminal program, but they’re on the remote server). To create a new window, use
C-b c; you can switch to different windows with their numbers, i.e.C-b 1,C-b 2, etc. - Splitting the window into multiple panes with
C-b %(vertical split) orC-b "(horizontal split). You can cycle between these panes withC-b o. - Scrolling back by entering
C-b [, then using PageUp/PageDown. - Having multiple sessions with different names, and connecting to the one you choose.
See the man page for many more capabilities of tmux.
You can read the man page directly in your terminal with man tmux.
Notes on the Tux Cluster
If you are a Drexel student working with the CCI Tux cluster (tux.cs.drexel.edu), note that it is a cluster of multiple machines, and SSHing to tux will actually connect to you one of the nodes at random. If you connect to tux, start tmux, and detach, you need to connect to the same node in order to re-attach to your session. You can do this either by re-connecting until you’re connected to the same node, or if you are on-campus by directly connecting to the specific node (e.g. tux5.cs.drexel.edu).
Alternatives
If tmux is not available, screen has similar capabilities, but with different shortcut keys. I usually recommend using tmux.
Zellij is a new alternative to tmux with a prettier user interface and much better built-in discoverability of its features. However, due to its more sophisticated use of terminal capabilities, I find it to be rather unreliable when it is unexpectedly disconnected (e.g. the network drops and I lose my SSH connection), leaving my terminal in a confusing state that requires manual resetting. I therefore returned to tmux after using Zellij for a few months, but you might find it useful. It is much rarer to find Zellij pre-installed on a compute server, though; most compute servers (including all the ones of interest at Drexel) have tmux these days.