Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From X(7) man pages

       From the user's perspective, every X server has a display name of the form:


    To avoid confusion, each display on a machine is assigned a display
    number (beginning at 0) when the X server for that display is started.

How can I find the display number I have been assigned?

Or list currently open displays and their users?

share|improve this question
up vote 7 down vote accepted

If you know of one process ID running in the user’s session, and you have permission to access that process’ information, you can grep its environment for the DISPLAY variable:

cat /proc/$pid/environ | tr '\0' '\n' | grep '^DISPLAY='

As an example, to list all the main displays used by your UID on the current computer, use:

ps -u $(id -u) -o pid= | \
    while read pid; do
        cat /proc/$pid/environ 2>/dev/null | tr '\0' '\n' | grep '^DISPLAY=:'
    done | grep -o ':[0-9]*' | sort -u

If you are only logged in to one X session, the above should output only one line with something like :0.

share|improve this answer
Note: If you wanna use this on one line, you need to add a ; before the done. – user1147688 Jun 7 at 8:48
@user1147688 thanks, but a newline character works just as well, at least in the shells that I use (Bash and Dash). – Amir Jun 7 at 12:22

In the X session, you can always consult the DISPLAY environment variable to get you current display number (echo $DISPLAY).

Finding out others' display numbers is tougher. I don't think there is any standard way of getting the information other than asking all the users which display they are connected to, so any attempt to gain this information requires some sort of hackery and will not work for all cases.

There are some options given elsewhere in SE but they won't work on Debian Wheezy, for instance. However, listing the displays currently active is easy, as shown in the post I linked above:

ps axu | grep "X " will show you the X processes that are currently running, something like the following:

root      2354  0.0  0.5  23380 18292 tty8     Ss+  Sep15   2:36 /usr/bin/X :1 vt8 -br -nolisten tcp -auth /var/run/xauth/A:1-7xlyuc
root      7901  0.0  0.3  17044 12072 tty7     Ss+  Sep14   5:58 /usr/bin/X :0 vt7 -br -nolisten tcp -auth /var/run/xauth/A:0-wckh0a

The first parameter after /usr/bin/X is the display number prefixed by colon, and the next one shows you the virtual terminal assigned to the session.

You might get you answer from looking at the process list, though:

ps axu |grep -3 "X "

root      1990  0.0  0.0      0     0 ?        S    Sep14   0:00 [kjournald]
root      1991  0.0  0.0      0     0 ?        S    Sep14   0:00 [kjournald]
root      1992  0.0  0.0      0     0 ?        S    Sep14   0:00 [kjournald]
root      2354  0.0  0.5  23380 18292 tty8     Ss+  Sep15   2:36 /usr/bin/X :1 vt8 -br -nolisten tcp -auth /var/run/xauth/A:1-7xlyuc
root      2359  0.0  0.0   5264  2228 ?        S    Sep15   0:00 -:1            
user_1     2378  0.0  0.0   4920  1348 ?        Ss   Sep15   0:00 /bin/sh /usr/bin/startkde
user_1     2443  0.0  0.0   3868   348 ?        Ss   Sep15   0:00 /usr/bin/ssh-agent env TMPDIR=/var/tmp /usr/bin/dbus-launch --exit-with-session /usr/bin/openbox-kde-session
root      7500  0.0  0.0   6460  1080 ?        Ss   Sep14   0:00 /usr/sbin/sshd
ntp       7841  0.0  0.0   5352  1760 ?        Ss   Sep14   0:17 /usr/sbin/ntpd -p /var/run/ -g -u 108:111
root      7882  0.0  0.0   3964   716 ?        Ss   Sep14   0:00 /usr/bin/kdm -config /var/run/kdm/kdmrc
root      7901  0.0  0.3  17044 12072 tty7     Ss+  Sep14   5:59 /usr/bin/X :0 vt7 -br -nolisten tcp -auth /var/run/xauth/A:0-wckh0a
root      7906  0.0  0.0   5260  2224 ?        S    Sep14   0:00 -:0            
user_2    7925  0.0  0.0  12924  1560 ?        Ssl  Sep14   0:00 /usr/bin/lxsession -s LXDE -e LXDE
user_2    7990  0.0  0.0   3868   348 ?        Ss   Sep14   0:00 /usr/bin/ssh-agent env TMPDIR=/var/tmp /usr/bin/dbus-launch --exit-with-session /usr/bin/startlxde

Look at the lines after /usr/bin/X - as the X session starts, a window manager is typically started as the user the session belongs to, and there you get the username. In my case user_1 is using KDE and user_2 is using LXDE. However, this solution relies purely on the fact that the kernel happens to be assigning new process IDs in ascending sequence, which might not be the case always.

share|improve this answer
Thanks, consulting DISPLAY is the answer I think. However, the DISPLAY variable may be outdated. This happened to me when reattaching to a screen session. It caused graphical things not to work. I solved it by detaching, echoing DISPLAY, reattaching, and setting DISPLAY to the new value. – ricab Sep 19 '13 at 13:02
Linux exposes the environment of each process under /proc/$pid/environ, as in cat /proc/$$/environ | tr '\0' '\n' | grep '^DISPLAY='. See my answer for another usage example. – Amir Sep 20 '15 at 9:51

termsql is a good tool to use for extracting information like that.

Finding out the DISPLAY number is one of the examples:

export DISPLAY=$(ps aux | termsql "select COL11 from tbl where COL10 like '%Xorg.bin%' limit 1")

(set DISPLAY environment variable to what display X is running on right now, assuming that the X binary is called "Xorg.bin")

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.