title: How to check if X server is running?
body: <p>Is there any way to find out if the current session user is running an Xserver (under Linux) ?</p>
  <p>I've started off with things like:</p>
  <pre><code>ps -e | grep X 
  </code></pre>
  <p>but this doesn't work always</p>
  <p>and one more thing I tried is checking the <code>$DISPLAY</code> variable</p>
  <p>Are there any other ways to check this?</p>
  <p>EDIT:</p>
  <p>Some people suggested using the <code>$DISPLAY</code> variables but what if the user fiddles with this variable ? what if he tries to do something and changes this variable and then when I check it, it no longer reflects an accurate state of the system.
  Is there no specific way to do this that will always return a correct answer ?</p>
  <p>I found that it can be done programmatically thus:</p>
  <pre><code>#include &lt;X11/Xlib.h&gt; 
  int main()
      { exit(XOpenDisplay(NULL) ? 0 : 1);  } 
  
  $ gcc -o xprobe xprobe.c -L/usr/X11R6/lib -lX11 
  </code></pre>
  <p>But I am looking for a script way.</p>