Re: Multiple X Sessions

From: Bob Stockler (bob_at_trebor.iglou.com)
Date: 10/19/05


Date: 19 Oct 2005 16:25:03 -0400

Roger Cornelius wrote (on Wed, Oct 19, 2005 at 11:37:41AM -0700):

| Bob Stockler wrote:
| > Roger Cornelius wrote (on Mon, Oct 17, 2005 at 05:01:00PM -0700):
| >
| > | Jean-Pierre Radley wrote:
| > | > Roger Cornelius typed (on Mon, Oct 17, 2005 at 11:52:12AM -0700):
| > | > | Bob Stockler wrote:
| > | > | > Roger Cornelius wrote (on Mon, Oct 17, 2005 at 09:58:37AM -0700):
| > | > | > | Bob Stockler wrote:
| > | > | > | > Will MP2 make possible more than one X session?
| > | > | > |
| > | > | > | It's already possible. Just supply an unused session number as an
| > | > | > | argument to startx. E.g., if you already have session 0, use:
| > | > | > |
| > | > | > | 'startx -- :1' (or 2, 3, etc.)
| > | > | > |
| > | > | > | Look in /dev/X to see what sessions are already active.
| > | > | >
| > | > | > Thanks, that works great!
| > | > | >
| > | > | > On OSR 5.0.6 I was used to just executing startx alone and it
| > | > | > would automatically pick the next available session number.
| > | > |
| > | > | Me too. I wrote my own script to determine the next session number,
| > | > | then exec the real startx with the necessary args.
| > | >
| > | > So would you contribute to the prevention of re-invented wheels? :-)
| > |
| > | What follows is basically what I use. I've excluded some non-relative
| > | stuff to select which window manager to use. It isn't perfect. E.g.,
| > | if you have servers 0 and 2 running, it will start server 3 rather than
| > | server 1. I doubt this would be a problem for anyone though. It also
| > | doesn't check to see if the serv3rs listed in /dev/X are actually
| > | running. Once, after rebooting when the machine hung, there were
| > | leftover entries in /dev/X. Again, that probably woudn't be a problem
| > | for anyone.
| > |
| > | I'm sure Bob can improve on this.
| >
| > Thanks for the compliment (or was it a challenge?). Anyway . . .
|
| It was meant to be a compliment.
|
| > #!/bin/ksh
| > # @(#) xstart - Start X using the lowest unused session number.
| > : ${AWK:=$(whence mawk)} ${AWK:=$(whence gawk)} ${AWK:=$(whence awk)}
| > eval $(
| > ps -ef | $AWK '
| > $8 ~ /^X/ { session[$9] = $9 }
| > END {
| > for (i=0;i<=10;i++) { ss = ":" i
| > if ( session[ss] != ss ) { print "session=" ss ; exit }
| > }
| > }'
| > )
| > [[ $session = ":10" ]] && {
| > print "\n All X sessions are in use.\n" ; exit
| > }
| > print "exec /usr/bin/startx -- $session"
| > exec /usr/bin/startx -- $session
| > # EOF xstart
|
| That does eliminate the problems in my script, but at the expense of
| forking two additional processes (mine forks none). Can you do it
| without the additional processes (this IS meant to be a challenge :))?

No, I can't do it - at least not readily - because my script
is broken (and your script is too).

I have 3 X sessions running - :0, :1 and :2. My script says
the next one should be :2 and your script says :4.

  [trebor] ~: l /dev/X
  total 0
  drwxrwxrwx 2 root sys 96 Oct 14 10:29 ISCCONN
  prw-rw-rw- 1 root group 0 Oct 13 19:49 Nserver.0
  prw-rw-rw- 1 root sys 0 Sep 12 13:00 Nserver.1
  prw-rw-rw- 1 root sys 0 Sep 17 14:15 Nserver.2
  -rw-rw-rw- 1 root sys 0 Sep 12 12:37 Nserver.3
  crw-rw-rw- 3 bob group 35, 0 Oct 19 11:58 server.0
  crw-rw-rw- 3 root sys 35, 4 Oct 19 12:09 server.1
  crw-rw-rw- 3 root sys 35, 7 Oct 17 13:40 server.2
  crw-rw-rw- 3 bob group 35, 5 Oct 17 12:46 server.3
  [trebor] ~: l /tmp/.*lock
  -r--r--r-- 1 root group 11 Oct 13 19:49 /tmp/.X0-lock
  -r--r--r-- 1 root sys 11 Oct 14 10:29 /tmp/.X1-lock
  -r--r--r-- 1 root sys 11 Oct 17 13:38 /tmp/.X2-lock

I'll have a look at using the .X?-lock files in /tmp and do it
all in the KornShell (even if I have to resort to ksh93).

Bob

| > | #!/bin/ksh
| > |
| > | # If an xserver is already running, start the next one
| > | # This was automatic with osr507 and earlier, but not OSR6
| > |
| > | startx_arg= # argument we pass to /usr/bin/startx, if
| > | any
| > | proto="/dev/X/server.*"
| > | set -A xs $proto # list of running X servers
| > |
| > | if [[ "${xs[@]}" != "$proto" ]]
| > | then
| > | # if server(s) already running, determine what next one s/b
| > | typeset -i n=${xs[${#xs[*]}-1]##*.}+1
| > | startx_arg="-- :${n}"
| > | fi
| > | unset n proto xs
| > |
| > | exec /usr/bin/startx $startx_arg

-- 
Bob Stockler  +-+  bob@trebor.iglou.com  +-+  http://members.iglou.com/trebor
Author: MENU EDIT II - The BEST Creator/Editor/Manager for filePro User Menus.
Fully functional (time-limited) demos available by email request (specify OS).


Relevant Pages

  • Re: Address Book for All Users Points to the Same wab file
    ... MAKE SURE THAT YOU DOWNLOAD THE VB FILE - DON'T EXECUTE IT! ... Then I opened the VB script using NotePad and set up my path the ... [Notice the two instances of Bob] ... >>> logging on into those accounts. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: ADO and blank fields problem
    ... > My script is a front end for an MS Access database. ... Bob Barrows ... Please reply to the newsgroup. ...
    (microsoft.public.scripting.vbscript)
  • Re: Reboot Script
    ... Conley typed: ... I created this script ... And It will delete the files for bob, but when I change bob to ...
    (microsoft.public.windows.terminal_services)
  • Re: Help with VB code - average of numbers over specified weeks
    ... Thanks, Bob. ... Dim iStart, iEnd ... I need help with creating the VB script that when run adds the totals ... Then the user clicks an ok button and the script runs. ...
    (microsoft.public.excel.programming)
  • Re: Script Error
    ... Bob wrote: ... > taskbar, I receive the following error message: ... > Internet Explorer Script Error ... > An error has occurred in the script on this page. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)