Feb 221999

screen – how to detach a session from your window

This article tells you how to install screen, "a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells)" [that quote shamelessly stolen from man screen].

Why use screen?

If you are a dialup user, screen will allow you to save your session, hang up, and at a later time reconnect and restart your session.  If you have only one phone line, that will allow to you make another phone call, save a running job, etc.  I’ve already found it to be useful and I’ve only used it once so far!

Installing screen

Here’s how I installed screen.  Remember, I already had the entire ports tree.  You may have to refer to the FreeBSD Handbook to see how to install a port.
# cd /usr/ports/misc/screen
# make
# make install

Using screen

To start a new screen session, just enter screen.  Then start what ever processes you want.  To detach a screen session,  type "^a d" (that’s "control-a" followed by a "d" for detach).  The session will then be put into the background.  To reattach a session, type screen -a.

It’s kind of hard to demonstrate this in written form, but I suggest you give it a try.   Remember to read the man pages for screen!

Also, you can create a screen session by typing something like this:

screen -S top10 top 10

and it will give you a screen session running the top 10 command.

And you can reattach to a session by typing screen -r which will give you a list of the screen sessions:

[dan@ns:/usr/home/dan] $ screen -r
There are several screens on:
        12551.top5      (Detached)
        12554.top10     (Detached)
        12476.top1      (Remote or dead)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

In the above, if you want to go back to the screen we started above, you would type:

screen -r top10

See man screen for more details.