[ale] How to tell if X is up?
hirsch at mathcs.emory.edu
hirsch at mathcs.emory.edu
Fri Jul 23 15:15:03 EDT 1999
Dan Newcombe <Newcombe at mordor.clayton.edu> wrote:
> On Wed, 21 Jul 1999 linuxhat at mailandnews.com wrote:
> > On 21 Jul 1999, Dave Brooks wrote:
> > Should have been more clear. *from within a C program*, how can we tell
> > if X is up and accepting connections on the local machine? (also, from
> > within a script, the above would have to be just a little bit smarter....)
>
> #include <X11/Xlib.h>
> #include <stdio.h>
> int main(int argc,char *argv)
> {
> Display *display;
> display=XOpenDisplay(NULL);
> if(display==(Display *) NULL) {
> printf("Server not accepting connections\n");
> return(1);
> }
> return(0);
> }
>
> This works for me. If I set my DISPLAY variable to a valid X server
> accepting connections, then it works. If I set it to a machine without an
> X server (ie. NT :) then it prints the string.
>
> This should be more portable than checking for the existence of a file
> someplace.
In the question he asks about the "local X server". If your display variable
points to a remote server this code will test that server. It is not clear to
me whether this is the desired behavior.
--Michael
More information about the Ale
mailing list