[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to determine from script if/where X is running



Hi,

I am not sure if I understand the situation completely, but

* like other Debian /etc/acpi scripts, you could run through /tmp/.X11-unix/X[0-9] which will point to locally running X servers, at least those that use UNIX sockets.

* to directly reach the X server on the currently selected VT, you could create a key event with acpi_fakekey and have the window manager that is reading the local keyboard or xbindkeys handle the xrandr stuff. Of course, that again requires these programs to run. Alternatively, Xorg can natively bind resolution changes to hotkeys which should be configurable through XKB.

* to find out about the VT for X servers (if they haven't been started with the 'vtxx' command line argument to begin with), you could grep the log files, they should contain something like '(++) using VT number 7'. If the location of the logfiles is unknown (which would indeed be a bit strange), lsof could help.

* Another possibility for the latter is 'fuser /dev/tty*' which prints the TTY-owning PIDs, amongst them the X servers'.

* The currently active VT can be determined with 'fgconsole'.

HTH
Raimund


Martin Kraus wrote:
On Wed, Mar 26, 2008 at 06:38:31PM +0100, Sven Joachim wrote:
Hello Martin,

On 2008-03-26 16:25 +0100, Martin Kraus wrote:

Hello,
  is there a standard way in debian to determine on what VT and display is X
running? Say I have a script that does something and I need to return output
to the user, but the user can be in linux console or in X or X doesn't have to
be running etc. So I need to determine if/where I should popup a window or
if I just need to send text to the console.
Most programs simply check for the DISPLAY environment variable.  This
is not totally reliable as it can be changed at will, but if the user
messes around with that variable, it is considered his fault.  And
you're in good company.

this doesn't help me when running programs from daemons of cron jobs. say we
have a system like this:

martin   tty1         2008-03-26 12:47
martin   tty2         2008-03-26 19:00
martin   tty3         2008-03-26 20:10
martin   pts/0        2008-03-26 12:47 (:0.0)
martin   pts/1        2008-03-26 12:47 (:0.0)
martin   pts/2        2008-03-26 12:51 (:0.0)
martin   pts/3        2008-03-26 12:54 (:0.0)
martin   pts/4        2008-03-26 13:23 (:0.0)
martin   pts/6        2008-03-26 20:09 (:2.0)
martin   pts/5        2008-03-26 18:52 (remote.server.example)
kb       pts/7        2008-03-26 20:11 (:2.0)

and what I would like to do is through keyboard hotkey, that runs an acpi
script, change a hardware display expansion on my thinkpad with widescreen.
now if I do this in the 1280x768 resolution the system display screwes up. so
I need to change the resolution do 1024x768. console with framebuffer is
already running in 1024x768 so I don't need to touch it and just tell bios to
trigger the display expansion. Xserver however needs to be resized. I can do
this throught xrandr. So I need to know, if what the current selected VT is and to determine if there is an
Xserver running on that VT. In the example above, there are three Xservers.
:0 and :2 are standard Xservers, :1 is Xephyr(ala Xnest). Now I need to know if there is X running on the current VT and also, what display is that X bound to. I could run who and just parse the display numbers and change the resolutions on all Xservers, but if no user is using any applications bound to that Xserver, it will not display in the "who" output.

This example is overcomplicated, but for the sake of argument, how would I go
about finding binding between Xserver display number and VT console?
If I parse output of ps I get this for Xserver with display :0:
/usr/bin/X11/X -nolisten tcp

which doesn't tell me the display number. I guess I would find hacks for
finding the display number for all running Xservers and just change resolution
on all of the, which is probably the best way, but is there a standard way to
do this in debian? I've noticed, that for example powersaved tried to do
something like this to decide where and how to output battery critical
information but even the debian package didn't work for debian, because
powersave assumed, that it can find display number in /proc/pid/cmdline but
it's not there.

So to sum it all, it's actually three questions. How to find display number
for X server in a standard debian way, how to determine on what VT what X
server is running and how to find out currently selected VT(since I assume,
there can be only one currently selected VT at any given time)

thanks
mk




Reply to: