If there are multiple X Windows running on a system, is it possible get a program to run on a particular window? How would you identify the Window and get the program to run there?

I'm assuming that I have whatever permissions are necessary to run such a program.


2 Answers 2


X programs know which X session they're supposed to talk to by looking at the DISPLAY environment variable.

First you'll need to find out what DISPLAY is set to in the X session where you want your program to run. Do this by issuing the command echo $DISPLAY inside an X-terminal in that X session. Typically get something like :0.0 is outputted.

Lets say you want to start the excellent program xclock program in your X session where DISPLAY is :0.0, but you want to do this at the console. You then press Alt-Ctrl-F1 to shift to that console, and then type:

DISPLAY=:0.0 xclock   # variables set w/ a command are local to that command

Then you go back to X by pressing Alt-Ctrl-F7 or Alt-Ctrl-F8 (or maybe some other F key, depending on your Linux flavor) and watch the new pretty wallclock you have there.

In fact you could've executed the above command in any shell on that same machine (via SSH, in any X session, on any console etc.) – the fact that you specified DISPLAY=:0.0 before the command means that the xclock window will always pop up in the same X session.

In fact – apart from the fact that X programs look at it – there is nothing special about the DISPLAY variable. Normally when you're starting programs from an X terminal they start in the right place because DISPLAY has already been set for you.

Instead of using the above command, you can also split it into two by first setting DISPLAY, and then running xclock. In this case the DISPLAY setting will persist until you close that shell, and all subsequent X programs started from there will open in the same X session as xclock.

                      # variables set w/o a command are local to the shell,
export DISPLAY=:0.0   # unless exported
  • 1
    Note that the last bit won't work unless you export the shell variable to the environment first though. Commented Nov 19, 2013 at 1:49
  • I think DISPLAY will be set to export by default, since it is imported by the shell (it works in both zsh and dash for me without using export). But, yes, if you can't get the two line version to work, try replacing DISPLAY=:0.0 with export DISPLAY=:0.0.
    – zrajm
    Commented Nov 19, 2013 at 2:08

Normally, the X client programs use the DISPLAY environment variable to know which X server display to connect to. Some programs also accept a command-line parameter (-display or something similar) which can be used to override the DISPLAY environment variable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .