[ale] How to tell if X is up?

linuxhat at mailandnews.com linuxhat at mailandnews.com
Wed Jul 21 17:04:53 EDT 1999


On 21 Jul 1999, Dave Brooks wrote:

>Yup.  Do this:
>
>elysium:[~]% ps aux | grep X
>root     21976  1.0 16.3 24720 20900 ?       S    Jul20  13:48
>/usr/bin/X11/X -a
>dbrooks  24198  0.0  0.3  1152  440 pts/2    S    14:51   0:00 grep X

>> Is there a good way to tell if the X server is up on the local machine?
>> We tried trapping the error on opening the display, but when we did
>> that, one of the routines called exit() instead of just returning an
>> error... more details if necessary...

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....)

[root at localhost /proc]# ps aux | grep X
root       561  0.0  1.7  2388 1084 ?        S    16:28   0:00
/etc/X11/prefdm -
root       565  0.6  6.8  8280 4304 ?        S    16:28   0:08
/usr/bin/X11/X -a
root       568  0.0  2.5  3124 1588 ?        S    16:28   0:00
/etc/X11/prefdm -
root       693  0.0  0.6  1148  392 pts/0    S    16:48   0:00 grep X

I noticed something... on Linux, X creates /tmp/.X11-unix/X0, and then
apparently deletes it when it's done.  Can this be relied upon?  If
that's so, we can simply stat(2) the named socket and be done with it.

-- Glenn






More information about the Ale mailing list