Re: how to determine from script if/where X is running
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)