Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
- Subject: Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)
- From: "Andrew J. Hesford" <email@hidden>
- Date: Sun, 18 Nov 2007 17:01:09 -0600
On Nov 18, 2007, at 4:31 PM, Nathaniel Gray wrote:
I'm pretty happy with the new way, but I *would* like a bulletproof
way of knowing if $DISPLAY is connected to a running X server. I've
got some code (mostly working around the lack of accessibility info in
X) that tries to connect to DISPLAY as a way of checking for a running
X server, since that seemed like the best way of detecting that.
Since that's no longer appropriate I need a replacement, and I really
hope you aren't going to say "ps -a -U $USER | grep X11" or some such.
;^)
Yes, grepping for X11 is an ugly solution. But you can't deny that it
works! Don't forget "grep -v grep" to avoid false hits when grep
matches itself.
Looking at the manpage, I don't see the facility for this, but I think
a nice way to do this (for general processes) would be to query
launchctl. Something along the lines of `launchctl status org.x.X11`.
The program could then print one of "running", "available" or
"disabled", depending on the job's status. It could also set a return
value based on the status. For example, 0 for "running" or
"available", 128 for "disabled". This allows you to do a bunch of tests:
if ! launchctl status org.x.X11 > /dev/null; then DONT_START_X_STUFF;
fi
if ! launchctl status org.x.X11 | grep running > /dev/null; then
X_NOT_RUNNING; fi
and so on. With these return codes, you have a quick check to
determine if you CAN do something with X. If you want to distinguish
between a running or available-to-run server, you have to take the
extra step with grep.
Of course, this isn't just limited to X11.
--
Andrew J. Hesford <email@hidden>
Department of Electrical and Computer Engineering
University of Illinois at Urbana-Champaign
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden