[ale] How to tell if X is up?
Michael D. Hirsch
hirsch at mathcs.emory.edu
Wed Jul 21 20:39:52 EDT 1999
linuxhat at mailandnews.com 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....)
There are several environment variables that should only be set when running
inside an X environment. The most obvious is DISPLAY. If it is set then
either X is running, or someone has misconfigured their environment. Of
course, it might not point to the local machine.
Other possibilities are XINIT_DIR and WINDOWID. I don't know how universal
setting these variables is, however. Both are defined on my RH 5.2 Linux box,
neither on my solaris box.
Another way with Linux and XFree is to look for /tmp/.X0-lock. If it isn't
there, then there is no X server on the usual port. The contents of this is
the pid of the Xserver. You should then check /proc to see if a directory with
that name exists. I have no idea if this will always work, or only for XFree
on RedHat. Also, it assumes you have the /proc filesystem.
--Michael
More information about the Ale
mailing list