Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations)



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)
Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/x11-users/email@hidden

This email sent to email@hidden
References: 
 >Re: Explanation of X implementations (From: John Bassett <email@hidden>)
 >Re: Explanation of X implementations (From: Ben Byer <email@hidden>)
 >Re: Explanation of X implementations (From: "Ambrose Li" <email@hidden>)
 >The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: Eric Gouriou <email@hidden>)
 >Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: "Ambrose Li" <email@hidden>)
 >Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: "Andrew J. Hesford" <email@hidden>)
 >Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: "Ambrose Li" <email@hidden>)
 >Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: Ben Byer <email@hidden>)
 >Re: The meaning(s) of $DISPLAY (was Re: Explanation of X implementations) (From: "Nathaniel Gray" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.