Running Multiple Sessions of X

Created on December 11, 1997
Last updated: October 3, 1998

I think this is very, very neat. I got it off of Linux Gazette Issue 23. Let me know if it works for you.

I would think that a lot of people would want to know how to run multiple X sessions; sometimes you have a different user who wants to log in and use X, but you're tied up downloading the newest version of WindowMaker with Netscape inside your own X session. Or something like that.

The solution? Run multiple X sessions. This can be done with only a few extensions to your command line. For your first X session, all you had to do was type startx, or if you run in high color mode like I do, you might have to type startx -- -bpp 24. That defaults to running it on screen 0, which is really your first X session.

What you want to do is make X run in screen 1 for the second, screen 2 for the third, screen 3 for the fourth, and so on. Here's how you would start a second X session:


startx -- :1

Now, if you run in high color mode, you would enter the proper paramaters after the :1 part of the command line. If you wanted to run in 24 bits per pixel (16.7 million colors), you would type startx -- :1 -bpp 24 as your full command line.

If you want to start yet another X session, a third one, you would type startx -- :2 and startx -- :2 -bpp 24 for 24 bit color. After that, you would use the numbers 3, 4, and 5 for additional X sessions.

Switching Between X Screens

You probably have a default number of 6 virtual consoles. Those are how many logins you can have in plain text mode, basically. If you have F12, you would probably have 6 "empty" screens if you're not running X.

Your first X session, as you may already know, is accessible by pressing Alt-F7 (use the left Alt key). For your second, it's Alt-F8. For the third, Alt-F9, and so on. This is what you would do to switch from text mode to an X screen.

If you want to switch from one X screen to another, you'll have to use Ctrl-Alt and then whatever F-key you'd normally use. For example, if you want to access X screen number 3, you'd press Ctrl-Alt-F9 from an existing X session. From text mode, you'd only have to press Alt-F9.

Suggestions

Tim Briggs previously sent in an e-mail concerning his frustration starting more than one X. He included it with a script, but then he sent in another version which is much cleaner and has a few improvements over his old one, which was previously posted here.

#!/bin/sh

if [ $# -eq 0 ]      # check to see if arguements are given (color depth)
       then a=16    # default color depth
        else a=$1    # use given arguement
fi

if [ $a -ne 8 -a $a -ne 16 -a $a -ne 24 ]
        then
                echo "Invalid color depth. Use 8, 16, or 24."
        exit 1
fi

for display in 0 1 2 3 4 5    # checks for open display, starts X on next available
        {
        if [ ! -f "/tmp/.X$display-lock" ]
                then
                        exec startx -- :$display -bpp $a
                exit0
        fi
        }
echo "No displays available."
exit 1

The way I manage multiple X seesions is put stuff in alias form in /etc/bashrc. You'll probably want to use Tim Brigg's script.

alias x="startx -- -bpp 24 -quiet &"
alias x2="startx -- :1 -bpp 24 -quiet &"
alias x3="startx -- :2 -bpp 24 -quiet &"
alias x4="startx -- :3 -bpp 24 -quiet &"
alias x5="startx -- :4 -bpp 24 -quiet &"
alias x6="startx -- :5 -bpp 24 -quiet &"

If you want to, go ahead and copy that to paste in your /etc/bashrc. You'll need to log out and log in again for the changes to take effect after changing that, and from then on those aliases will be carried in to all new logins.

When I type x it starts up my first X session. Then it starts up to 5 more X sessions. The first one is referred to as session 0, although it's actually number one. That's fairly common in Unix.

It's also worth noting that I put the ampersand ("&") at the end of the startx command line in order to make it run in the background. That way it frees up a text mode console for me instead of keeping it and making me log in again on another virtual terminal.

Related Pages

  1. Remote X
  2. Configuring and Troubleshooting X
  3. Installing and Upgrading X

Send all comments, questions, suggestions, corrections, and complaints joshuago at users dot sourceforge dot net.


Copyright © 1997-1999 Joshua Go (joshuago at users dot sourceforge dot net). All rights reserved. Permission to use, distribute, and copy this document is hereby granted. You may modify this document as long as credit to me is given.