[sf-perl] determining console or xwindows mode

Michael Paoli Michael.Paoli at cal.berkeley.edu
Sun Mar 21 12:51:43 PDT 2010

Well, first question would be exactly what you're trying to do, and why?

What if it's neither a Linux console nor some xwindow?

If you really need to know if it's running bare on a Linux console,
one can examine the output of tty - or better yet do what the
tty command does, readlink on /proc/self/fd/0.  Of course that's highly
Linux-specific, and one would still have to match the results to
possible Linux console devices.

In general, the better approach however, on, e.g. use X or not for
X capable program output is:
o If option/environment on program is set to not use X, don't use X
o notwithstanding the above, if DISPLAY is set, use X
o and of course check and do reasonable thing(s) in case of

Keep in mind:
o may be neither console, X nor X-capable (e.g. X not available and on
   terminal or pseudo-terminal)
o may be console, yet DISPLAY set and X fully available (e.g. user doing
   stuff from console, but prefers X capable stuff launch/display in X)
o may be in X (e.g. xterm) but DISPLAY may not be set (e.g. user just
   wants text mode behavior of stuff started from there)
o just because DISPLAY is set, doesn't mean it's useable (e.g. could be
   incorrect/vestigial setting, or don't have permission(s))

> Date: Sun, 28 Feb 2010 20:22:06 -0600
> From: Richard Reina <gatorreina at gmail.com>
> To: San Francisco Perl Mongers User Group <sanfrancisco-pm at pm.org>
> I have a program that must run differently in xwindows then it would on a
> linux console.  I was wondering if there's a function to determine if a
> program is running in a linux console or in xwindows so that upon execute
> it  can make the necessary accommodations?

More information about the SanFrancisco-pm mailing list