Search code examples
linuxpidx11

How do I get xid from pid (and vice versa)?


How do I get the pid from the xid (X window identifier)? How do I get the list of xids for a given pid?

(Assuming all applications run with DISPLAY=:0, without network transparency being in use)

I'm expecting something like:

  1. Dig in /proc/$pid/fd/ to track connection to X server
  2. Follow that connection, dig in /proc/`pidof X`/fd
  3. Dig inside X as it should know how to map connections to it to windows.

Solution

  • This works for my purposes:

    =^_^= izkata@Izein:~$ XID=0x340001c
    =^_^= izkata@Izein:~$ printf "%d\n" $XID               # Convert from hex to decimal
    54525980
    =^_^= izkata@Izein:~$ xdotool getwindowpid 54526066
    20639
    =^_^= izkata@Izein:~$ ps 20639
      PID TTY      STAT   TIME COMMAND
    20639 ?        Ssl  116:25 /usr/lib/firefox/firefox