Finding the DISPLAY associated with a process

Finding the DISPLAY associated with a process

Post by Kamalakar Malla » Sat, 15 Feb 1997 04:00:00



If a process was created by executing
an X Windows application, is there a way one can
find what is the DISPLAY for this process.

-Kamal

 
 
 

Finding the DISPLAY associated with a process

Post by Dan Merc » Sat, 15 Feb 1997 04:00:00


: If a process was created by executing
: an X Windows application, is there a way one can
: find what is the DISPLAY for this process.

: -Kamal

Get lsof from the net somewhere.  Assuming you know the pid (and you
don't have to,  lsof has a rich syntax for drilling down to the data)
the following would work (for most cases) in ksh

lsof -a -p$pid -iTCP:6000 -Fn |
   while read data
      do
      case "$data" in
         p*) ;; # ignore
         n*) DISPLAY=${data#n*>};DISPLAY=${DISPLAY%:*}:0;break;;
      esac
      done

# if DISPLAY is unset,  must be localhost connecting on UNIX domain socket
: ${DISPLAY:=$(hostname):0}

lsof -a -p$pid -iTCP:6000 -Fn |
      |   |        |        |
      |   |        |        |
      |   |        |        just output pid and netname
      |   |        |
      |   |        all xclients talk to remote servers on port 6000
      |   |
      |   PID to examinse
      |
      AND all conditions

output might be:
p7177
nclienthost.domain.name:1234->serverhost.domain.name:6000
nclienthost.domain.name:5678->serverhost.domain.name:6000
(multiple connections are possible,  as with HP-VUE's and CDE's window
managers)

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

Finding the DISPLAY associated with a process

Post by Michel Prévos » Sat, 15 Feb 1997 04:00:00



> If a process was created by executing
> an X Windows application, is there a way one can
> find what is the DISPLAY for this process.

> -Kamal

DISPLAY is an environment variable. You can get it with the getenv()
function.

But if you want to know which X-Server a process is client of, you
can use the XDisplayName().

Michel