Power backgrounding with 'screen'

Mar 15, '02 09:29:05PM

Contributed by: osxpez

One of my absolute favourite *nix-tools is screen. It allows me to start a lengthy and possibly talkative and interactive process and then detach from it at will. I can later attach to the process and then enter right into where it is at the moment.

You can install screen using fink (which has been discussed previously on macosxhints.com), or you can download the source and build it yourself from the screen home page on gnu.org.

Read the rest of the article for a theoretical example of how to use screen once it's installed.

The following is a fictive but plausible screen session. The gnome bundle is large and complex 'fink' package that takes quite a while to install; a perfect situation in which to use screen. So prior to starting the fink install, start a screen session:

 % screen
Then launch the fink installer for the gnome package:
 % fink install bundle-gnome
fink might ask me a couple of questions before it starts downloading. So I answer them and then when it starts downloading, I hit "control A" and then "d" (default detach key sequence). I can now log out. I can log in again hours later to see where the install process is at the moment:
 % screen -R
fink can now be downloading or compiling or whatever. It could also be asking me a question. Like if it has had problems getting a file and is asking if I wish to "Give up" or "Retry". I want fink to retry and tell it so. I can now detach (ctrl-a d) again. Hours later I can check in on the install process again using "screen -R".

This time maybe fink has told me the install was successful and I then see the shell prompt the screen started for me to begin with. I can then exit that shell:
  % exit
I get a message [screen exiting] (or something like that), and get back the prompt from where I wrote "screen -R".

I often start a screen right after I have logged in. Then I can detach at any time, even if I'm in the middle of editing a file in vim or some such and then reattach and continue editing later.

screen is almost to good to be true. =)

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020315212905291