Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sometimes I face some problems in display and mostly I do want to know which files or processes are using the DISPLAY environment variable.

So how to list all processes that having DISPLAY set?

share|improve this question

2 Answers 2

I came up to this command after many searches and tries:

for file in /proc/[0-9]*; do grep -ao 'DISPLAY=[^[:cntrl:]]*' $file/environ 2>/dev/null && grep -ao '(.*)' $file/stat; done | sed 'N;s/\n/\t/'

A sample of the output is:

DISPLAY=:0  (unity-files-dae)
DISPLAY=:0  (unity-music-dae)
DISPLAY=:0  (unity-lens-vide)
DISPLAY=:0  (zeitgeist-daemo)
DISPLAY=:0  (zeitgeist-fts)
DISPLAY=:0  (zeitgeist-datah)
DISPLAY=:0  (cat)
DISPLAY=:0  (unity-scope-vid)
DISPLAY=:0  (unity-musicstor)
DISPLAY=:0  (dconf-service)
DISPLAY=:0  (gdu-notificatio)
DISPLAY=:0  (telepathy-indic)
DISPLAY=:0  (mission-control)
DISPLAY=:0  (goa-daemon)
DISPLAY=:0  (VBoxXPCOMIPCD)
share|improve this answer
1  
Nice solution. Could you please add some explanation for what happens behind the scene? Also, the output is cropt, what can I do to get full process names? –  Danatela Mar 11 '14 at 8:57
1  
This command search recursively in the the /proc directory. grep for the DISPLAY in each file. Those files are in really the processes running so every file containing the word DISPLAY means that this process is using it. You can't get the full process name since the names in the output are the file names founded ion /proc so simply you can't know more than the offered. –  Maythux Mar 11 '14 at 9:04
    
PLease, edit your answer instead and just inform the user that you have updated your post. –  Braiam Mar 11 '14 at 12:43

Thats some pretty nifty command line scripting! Im gonna make a copy at that script in case I have to hack it to figure something else.

Ideally all the current processes that correspond to the programs that you execute on the local machine, post login, are gonna carry the same display variable as your first open pts (pseudo-terminal session) console.

For instance when you open your first terminal session (gnome-terminal) and run the who or w command you will notice some output like this:

$ who

yourusername   :0        2015-06-08 14:05 (:0)
yourusername   pts/0     2015-06-08 14:22 (:0)

or some folks might look like this (but not it your case)

yourusername   :0        2015-06-08 14:05 (:0)
yourusername   pts/0     2015-06-08 14:22 (:0.0)

using the light display manager if the DISPLAY variable is set differently for post login execution of shells (e.g. :0.0), then the environment variable for DISPLAY would yield the same display variable as the post-login display variable of the first open pts (:0.0), but the host variable, at login, would still be (:0).

By echoing the DISPLAY variable, or running set piped to less as shown below:

:~$ echo $DISPLAY

or

:~$ set | less

you can also check your sessions current display variable, and see what it is set to, for post login execution of shells. So basically the display variable of the processes you execute, are gonna have the same display variable as your first open pts, post login.

The output of the script that you posted, suggests that your first open pts is gonna have the same display variable as your display manager's login, in this case :0.

Now for the second example the output would look something like this:

DISPLAY=:0.0    (gvfs-udisks2-vo)
DISPLAY=:0.0    (zeitgeist-daemo)
DISPLAY=:0.0    (zeitgeist-fts)
DISPLAY=:0.0    (zeitgeist-datah)
DISPLAY=:0.0    (gvfs-mtp-volume)
DISPLAY=:0.0    (gvfs-gphoto2-vo)
DISPLAY=:0.0    (gvfs-afc-volume)
DISPLAY=:0.0    (geyes_applet2)
DISPLAY=:0.0    (indicator-apple)
DISPLAY=:0.0    (cat)
DISPLAY=:0.0    (python)
DISPLAY=:0.0    (gvfsd-trash)
DISPLAY=:0.0    (indicator-keybo)
DISPLAY=:0.0    (gvfsd-burn)
DISPLAY=:0.0    (cat) 
DISPLAY=:0.0    (cat)
DISPLAY=:0.0    (gnome-terminal)
DISPLAY=:0.0    (bash)
DISPLAY=:0.0    (bash)
DISPLAY=:0.0    (sed)

Also for additional reading you can look at the the man pages for ptmx

$ man ptmx

This might lend you some insight into the master-slave relationship of pseudo-terminals.

I hope this helps!

Also where did you get that script at?

share|improve this answer

Your Answer

 
discard

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.