[SOLVED] What is the purpose of the DISPLAY environment variable?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What is the purpose of the DISPLAY environment variable?
I have seen that many GUI programs have a command line argument like --display. I found out that if no such argument is specified, the DISPLAY environment variable is used to determine which X server the program should connect to. I always thought that the display manager such as gdm or kdm connects directly to the X server, and that other programs should connect to the display manager. So now I am a little confused. Could anyone explain to me why programs connect directly to X servers, why use display managers if the above is the case, and what exactly happens when a window is made visible?
The function of the display manager is to manage the X server instances, not to mediate the applications. The applications communicate directly to the X server.
So it is quite possible to run X without a display manager (and on an old system, is a good way to save some memory!). It is just a matter of calling xinit directly with appropriate parameters.
You can even do without a windows manager for that matter, if you don't need to shuffle windows around, for example when creating a kiosk platform.
Last edited by neonsignal; 11-11-2010 at 07:54 PM.
all a windows manager does is give a display window for the Xserver to render TO. Xserver is in charge of all display rendering. The DISPLAY variable tells which display to which to send the rasterized image, which is usually at :0. for example, if you were to install xserver-xorg on an ubuntu box that had no window manager installed, and then sshed into it from a box WITH a window manager with the -X (X11 forwarding) option set, and entered a command such as xlogo, you would receive an xlogo window on the client machine, even though the server does not have a window manager installed.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
as said before, the DISPLAY variable is to help sort out multiple instances of the X server (such as in a dual head situation the left monitor may be :0.0 and the right may be :0.1, or a multi seat situation, seat 1 may be :0 seat 2 :1 seat 3 :2 etc..., another example would be using Xephyr or Xnest to run a nested X session within another X session the main one would be :0 the second would be :1, and last but not least VNC would also use separate DISPLAY environments for each instance of VNC server) these are only a few examples
that being said you can also from the command line with some programs implicitly tell a program to start on a given display using something like --display :X(.x) or -display :X(.x) assuming your user account has privileges to USE the specified display.
X is a program that runs on the computer very soon after the kernel loads. Almost all graphics that must be displayed on the monitor are sent to the X server. Other programs send their GUI images and other window info to the X server. The desktop manager contains information about what programs should startup, what the desktop should look, etc. and sends images to X also. The window manager manages switching between windows, z-ordering of windows, what gets painted and what doesn't, where windows are, etc. And then there is the compositing manager, which I guess intercepts or intervenes between the programs and X and offers an API for manipulating the image(s) before they are sent to the X server.
Just a small terminology clarification: the "desktop manager" refers to the program that starts the X server (usually all you see of it is the username/password prompt). The look and feel of the desktop revolves more around what is called the "desktop environment", which is a loose term encompassing the look of the desktop and the various programs that provide menus, file browsing, settings, and so on.
The X server does start towards the end of the initialization on a desktop distro, but it is typically invoked by the desktop manager (eg gdm, kdk, or xdm).
Last edited by neonsignal; 11-12-2010 at 08:17 PM.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
one more clarification, the X server does not have to be running on the same machine, there are X servers for windoze as well, in that case you run the X server, connect to a remote machine (usually with SSH with X forwarding enabled) and then you can run remote X programs from that machine on the local X server, in this manner X11 is a reverse client server since the SERVER program runs locally and the clients are run remotely, yes its confusing but thats how it works
I think I understand most of it now. I read somewhere that X really is a server that runs in the background and clients connect to it through sockets. Usually the X server on the client machine and is accessed via the loopback network interface. This is, I believe, an X server can be run on a remote computer and be displayed on a remote computer.
One more question: I know that this is how an X server is referenced:
host:x.y
The "host" is the server computer (usually 127.0.0.1, localhost, or blank) and "x" is the instance of the X server running on the "host", but what is "y"?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
y is the screen such as in multi-head set-ups :0.0 would be screen 1, :0.1 would be screen 2 etc.., however when using Xinerama for instance :X.1 to .X.n are transparently merged and all behave one virtual screen, :X.0
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
your welcome, and yes it often represents a monitor but also it could be a virtual display such as with Xnest or Xephyr or vnc, and welcome to lq btw i forgot to say that the first time i replied
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.