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:
/proc/`pidof X`/fd
You could use xprop -id <windowid> _NET_WM_PID
to get the PID property of the window in question. You should know the window id of the window and not all applications set the _NET_WM_PID
atom.
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
wmctrl lists windows, their xids and optionally the pid of their process. So assuming there is only one window with your $pid
, you could get the corresponding xid with
wmctrl -ulp | tr -s ' ' | cut -d" " -f1,3 | grep $pid | cut -d" " -f1
and conversely, assuming the xid is in hexa,get the pid
wmctrl -ulp | tr -s ' ' | cut -d" " -f1,3 | grep $xid | cut -d" " -f2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With