How to get window ID from process ID

You can get the list of matching windows via

 xdotool search --pid [pid]

also see xdotool help search


It's been discussed in the "other" forum:

  • Is there a linux command to determine the window IDs associated with a given process ID?
  • How to get an X11 Window from a Process ID?

In the first, @Patrick points out that xwininfo can return information on all windows, and by using xprop for each window, you can check for the _NET_WM_PID property, matching it against your process-id.


I will use this simple command to get the window ID in hex format

wmctrl -l | grep -i xterm | awk '{print $1}'

For decimal format, bc command can be used for conversion

echo "ibase=16; `wmctrl -l | grep -i xterm | cut -c 3-11 | tr a-z A-Z`" | bc