Is there any way to find out if the current session user is running an Xserver (under Linux) ?
I've started off with things like:
ps -e | grep X
but this doesn't work always
and one more thing I tried is checking the $DISPLAY
variable
Are there any other ways to check this?
EDIT:
Some people suggested using the $DISPLAY
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 ?
I found that it can be done programmatically thus:
#include <X11/Xlib.h>
int main()
{ exit(XOpenDisplay(NULL) ? 0 : 1); }
$ gcc -o xprobe xprobe.c -L/usr/X11R6/lib -lX11
But I am looking for a script way.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…