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

Re: test if x server is running on a given display



On Fri, Sep 17, 2004 at 12:02:08PM -0400, Matt Price wrote:
> Dave Howorth wrote:
> 
> >>know whether there's a way to contact the server directly to see 
> >>whether it's
> >>REALLY running....
> >
> >
> >The simplest way to me is to write an X client program that just makes a 
> >connection, then disconnects. Something like this in fact:
> >
> >#include <X11/Xlib.h>
> >#define DISPLAY ":0.0"
> >
> >int main(argc, argv) int argc; char **argv; {
> > exit(XOpenDisplay(DISPLAY) ? 0 : -1);
> >}
> >
> >Then cc -L/usr/X11R6/lib -lX11 xtest.c
> >
> >Cheers, Dave
> >
> >
> thanks dave, that's very cool.  now... I don't program in c.  would it 
> be easy to modify this program in two ways:
> 1) pass the display number as a parameter
> 2) print or return a specific error message if the connection is not 
> accepted?
-- NEW VERSION --
#include <X11/Xlib.h>

int main(argc, argv) int argc; char **argv; {
 exit(XOpenDisplay(NULL) ? 0 : 1);
}
-- END --

$ gcc -o xprobe xprobe.c -L/usr/X11R6/lib -lX11


Now:

xprobe from an xterm:   Connects to the xterm's server
xprobe from .xinitrc:   Connects to new server
xprobe from a VT:       Fails
DISPLAY=display xprobe  Connects to display 'display'

As for an error message, here's what I'd do:

xprobe || echo "Foo! server not responding?" >&2

> 
> Matt
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact 
> listmaster@lists.debian.org

-- 
The world's most effective spam filter:
        ln -sf /dev/full /var/mail/$USER



Reply to: