Andrew Wilkinson

Random Ramblings on Programming

Naming Screen Sessions

with 5 comments

I develop a number of Django-powered websites at work, and usually I want to leave them running when I’m not working on them so others can check out my progress and give me suggestions. The Django development server is incredibly useful when developing, but it’s not detached from the terminal so as soon as you log out the server gets switched off. One alternative is to run the website under Apache, as you would deploy it normally. This solves the problem of leaving the website running, but makes it much harder to develop with.

A third option is the GNU program Screen. When run without arguments screen puts you into a new bash session. Pressing Ctrl+d drops you back out to where you were. The magic occurs when you press Ctrl+a d. This drops you back out, but the bash session is stilling running! By typing screen -r you’ll reattach to the session and can carry on working as before. You can leave it as long as you like between detaching and reattaching to a session, as long as the computer is still running.

It is possible to run multiple screen sessions at once, perhaps with a different Django development server running in each. Unfortunately screen will only reattach automatically when there is just one detached session. If you have more than one then you’ll be confronted by a cryptic series of numbers that uniquely identifies each session. You can reattach to a specific session you can type screen -r <pid>.

To make things easier to reattach to the session that I’m working on I give these sessions name so rather than a cryptic series of numbers I see a useful set of names. To do this you just need to type Ctrl + A : sessioname <name>.

There are plenty of other useful things that screen can do, but named sessions is by far and away the most common one that I use.

Advertisements

Written by Andrew Wilkinson

February 3, 2010 at 1:27 pm

Posted in unix

Tagged with , , , ,

5 Responses

Subscribe to comments with RSS.

  1. You could also just use one screen session and create a new window inside your session with “^a c”. Than you can switch between windows with “^a n” and “^a p” (next and previous). You can also name windows and let screen display these names in a “tab bar”. Just google up “screen hardstatus”

    bjunix

    February 3, 2010 at 2:25 pm

  2. It’s also possible to name the screen when you create it, like so:

    screen -S nameofscreen

    Then when you want to attach to it later

    screen -r nameofscreen

    Also useful: multiple people can attach to the same screen with -x in place of -r.

    P. F. Hawkins

    February 3, 2010 at 2:31 pm

  3. Screen is nice, I usually just use nohup.
    nohup python manage.py runserver &

    Then everything is logged to nohup.log

    Justin

    February 3, 2010 at 4:36 pm

  4. ./manage.py runserver &

    done!

    juanpex

    February 3, 2010 at 7:39 pm

  5. Stuff started with `stuff &` runs in the background but is still attached to your session. When you terminate your session (eg, logout), it will terminate any background processes.

    Chris Webstar

    June 19, 2010 at 5:36 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: