Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: How to detect X?

by husker (Chaplain)
on Feb 21, 2005 at 23:02 UTC ( [id://433186]=note: print w/replies, xml ) Need Help??


in reply to Re^4: How to detect X?
in thread How to detect X?

So can you not check for BOTH a non-empty DISPLAY *and* check the process table (via ps or whatever is handy) for the X process?

Replies are listed 'Best First'.
Re^6: How to detect X?
by jdporter (Paladin) on Feb 22, 2005 at 04:41 UTC
    In general, no. Because in general, the X server (which DISPLAY is pointing at) may not even be running on the local machine. You'd have to have some way of checking for a running X server process on some other machine on the network, which itself is in general a "hard" problem. You'd do better just to check if you can make an X connection directly to the specified X server.
      In general, no. Because in general, the X server (which DISPLAY is pointing at) may not even be running on the local machine.
      But then again I'm interested in making the GUI version start automatically only if the/a X server is running on the local machine (unless explicitly stated differently by the user on the cmd line).

        Wha-?

        Only on the local machine?

        I beg of you - don't do that. First off, determining that the X server is running on the local machine is a hard problem. Secondly, why limit me at all? If I set my DISPLAY to "othermachine:8", why should that bother you? The X protocol handles this just fine!

        Proof that it's a hard problem: one machine at work doesn't have X loaded locally at all. But I use DISPLAYs of machine:2, machine:7, and localhost:10.0 (and others, but that's all I've got at this moment in time). None of them are "local" per se. The first two are VNC servers (different users). The X server is really running on that machine, but they're never visible on the monitor attached to the machine. The first one is only visible on my home computer (3000km away). The second is one I share with another coworker (we can both be on the phone and on VNC seeing the same screen). The third is my SSH tunnel which means the X server is actually physically at home, even though it says "localhost". (Which is faster, the VNC server or the SSH tunnel, depends on what I'm doing, so I have both, and use each when appropriate.) "machine:0" doesn't exist on this machine.

        Even using ":0" as the local display can be problematic since I can put VNC server on that port as long as the local X server isn't loaded. Or I can have two local X servers on two different monitors - thus one of them could be :1 (or :0.1, depending). Detecting this is a waste of time. If the user gives you a DISPLAY, use it. If they don't, don't. That's as smart as I would ever want my software to be. Anything else, and you're trying to outsmart me, when I'm merely using the X protocol to the fullest advantage I can. Remember: the user may know more about X than you do. Let them use that knowledge, and let your APIs deal with that.

        In that case, it's dead simple:
        use Sys::Hostname; sub run_with_gui { # returns boolean defined $ENV{'DISPLAY'} or return 0; my( $display ) = $ENV{'DISPLAY'} =~ /(.*):/; $display eq '' || $display eq hostname() }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://433186]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found