Use screen to keep sessions alive when you leave
What is screen
screen is a Linux tool to create seesions in your terminal, these sessions will remain alive even when you close your terminal, which happens quite often when running deep learning models on remote clusters.
Common usages
screen -lslists all sessionsscreen -S your-session-namecreates a new sessionscreen -r your-session-nameattach an existing session, you can just type in the first few lettersscreen -X -S your-session-name quitkill an existing session
I like shortcuts, I create a few and put them in ~/.bashrc, so I dou’t need to input these long commands
alias sls='screen -ls'
alias sr='screen -r'
alias sS='screen -S'
alias ns='nvidia-smi' # extra bonus
function sk() {
var=$(screen -ls $1|awk 'NR==2 {print $1}')
echo 'trying to kill' $var
screen -X -S $1 quit
}
When you are inside a screen session:
- press
control + A, release then pressDto detach the current session - press
control + D, quit the current session - press
control + A, release then type:sessionname new-session-nameto rename the current session.
Defects
- Sometimes I forget whether I’m in a session or which session I’m in, but I could not find a way to always show the current session name.