Screen
Intro
screen has 2 jobs:
- running processes, even when you're logged out
- TTY Multiplexer, also spawn several virtual terminals at a logic terminal.
With it you can easily run several programs in a logical terminal, regardless whether you are logged or not. In addition, you can remotely use screen from many computers attaching/detaching at will.
Basic Usage
Calling screen:
user@host:~ $ screen
Creating new virtual terminals:
^a^c (ctrl-a ctrl-c)
View available windows/terminals:
^a^w (ctrl-a ctrl-w)
Switch among virtual terminals:
^a^n, ^a^p, ^a^<number>
Detaching screen (screen keeps running in the background):
^a^d
Re-attaching screen: (reattach the screen you just detached):
user@host:~ $ screen -r
Detach an elsewhere running screen session and reattach to it in the current terminal:
user@host:~ $ screen -rd
screen end whenever all processes running in screen end and you eventually log out the shell. It'll display: screen is terminating
If a process hangs within screen or screen itself hags you should try ctrl-q and ctrl-a ctrl-q. If it doen't help, processes in screen can be killed with ak.
Screen can also distinguish visual bell vs audio bell. Whenever a process sends G (BEL) ''Screen'' either forwards it (audio bell) or signals the BEL with a short screen invertion. With a^g you can switch both methods.
Shell Titles, Margins, and Prompts
When using GNU Screen, the characters sent using the "Escape-k" shell-name-change sequence are included in the line count, which affects the "margin" count and "wrap" functionality of the current shell-input line.
To dynamically change the "shell title" of a GNU Screen shell while also dynamically changing the shell prompt, without affecting the "wrap" count, a "newline" must be sent between sending the shell title and the shell prompt; doing so resets the "wrap" count. Then, to minimize wasted vertical space on the console, one "cursor up" command is sent after the title-change command.
For example, in "bash":
if [[ "$TERM" =~ "screen" ]]; then # "GNU Screen" title-change command. echo -en "\ek$shellTitle\e\\" else # Generic terminal title-change command, echo -en "\e]2;$shellTitle\a" fi # Send one "cursor-up" command after the title-change command. echo -e "\e[1A"
The above may seem like a "hack" solution, but, for now, it works. Please amend this Wiki page if/when a better solution is/becomes available.