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