in reply to Checking X server status

Or check to see if the $ENV{DISPLAY} variable is set. If it is, X is running, if not, X is not running.

Replies are listed 'Best First'.
Re: Re: Checking X server status
by bikeNomad (Priest) on Jun 26, 2001 at 00:53 UTC
    No, you can have $DISPLAY set and not have X running. I've seen $DISPLAY set by login scripts before (not uncommon when the display is on a remote machine). Try this from a text console without X running:
    bash$ export DISPLAY=localhost:0 bash$ echo $DISPLAY

    Remember, your X server may not be on the local machine. I keep my $DISPLAY variable set on my embedded machines so I can run X programs on them at will, but don't actually start window managers for them, so most of the time $DISPLAY is set but the server might or might not be available.

    Also, you can have X running but not have a $DISPLAY environment variable set (like if you go to a text console on the same machine).

    This brings up the question of "what do you mean 'X running'?". Do you mean: is there one or more X servers going on this or some other machine, or is this program being run from within an X session? These are both tricky. My program just looks for a running X server at either $DISPLAY or localhost:0; if a server is not available, it returns 0.

Re: Re: Checking X server status
by mr_dont (Beadle) on Jun 26, 2001 at 00:35 UTC

    Oh yeah...

    I guess i need to read up on how X works! Thanks for the tips, monks!