[ale] How to tell if X is up?
linuxhat at mailandnews.com
linuxhat at mailandnews.com
Fri Jul 23 16:51:03 EDT 1999
On 23 Jul 1999, hirsch at mathcs.emory.edu wrote:
>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.
>
>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.
Close enough for government work. If we made sure "xhost + localhost" was
in the X initialization scripts and ran XOpenDisplay("localhost") we got
close enough to the desired behavior to be useful. Thanks, guys.
-- Glenn
More information about the Ale
mailing list