Quote:
Originally Posted by jpolcari
Surprised nobody got this yet.
Here's how I do it:
/usr/bin/xterm -e exit > /dev/null 2>&1
[ "$?" != "0" ] && exit
|
Sergei Steshenko did suggest that back in article
#10. He just didn't specify a particular program. Really, I don't see how running some other program with the possibility of it's failure is any different from running the program of principal interest, and having it possibly fail.
The only real test is to check whether there is a $DISPLAY variable set to a sane value, and then try to make an X connection to the indicated server. The X client application does that by default. One could probably contrive a special purpose application that does only that, and sets return values indicating success or its particular failure mode.
The problem with using the process table to check for a running X server is of course that the X server may not be running on the same host that the application will run on, and there is the possibility the any local X server is not named 'X', and that the X server may not be accepting connections from application(s) on the local host. There is also the possibility that the running X server does not support some other required functionality, such as video modes, fonts, etc. None of these conditions are easy to detect without simply trying to make the connection and use the server.
--- rod.