Sunday, April 17, 2005

Use the screen utility

Using the screen utility

If you quit one of the processes under screen's control (for instance, by typing q to top or typing exit at a shell prompt), that window will close. When its last window closes, screen, and its backend process, SCREEN, terminate.

If some screen windows are open, though, you can also leave screen temporarily. Here are two ways:

You can suspend screen by typing C-a z or C-a C-z from any window. You can restart it (before you log out!) by typing the shell's fg command. This uses Linux job control.

You can detach screen from your current terminal. The SCREEN backend process and the ptys it manages keep running. You can log out and log in again later -- even days or weeks later (as long as the system isn't rebooted) -- and reattach the SCREEN backend process to your new terminal. To detach screen from your terminal, type C-a d. You should see the message [detached]. Now you'll be back at a prompt from the shell where you first started (or attached) screen.

For example, if you're monitoring a long-running industrial process from a tty on your office workstation, and you're afraid that it won't finish before you have to go home, start that processes under screen control. When you leave, use C-a d to detach. Now you can turn off your display (but not your CPU!), go home, connect to your workstation by (for instance) ssh, and reattach. It's that easy!

To reattach, type the command screen ­r at a shell prompt. Your window should appear just as it was when you left it -- unless its contents have changed in the meantime, of course. You can see previous lines of the display by using screen's scrollback history.
Post a Comment