That's not mapping a PID to the window though - it's just destroying a window ID and seeing what happens to error out - which might not happen if the app was written to handle the window being destroyed outside it's control, or it's running on a different machine where you won't see any error output/a process dying.
https://gitlab.freedesktop.org/xorg/app/xkill/-/blob/master/...
It literally is using XKillClient - https://linux.die.net/man/3/xkillclient
You can kill the connection of another client if you know its id. That's one of the reasons why we love X11 so much.
Another way, as josefx mentioned, is to kill the PID from _NET_WM_PID window property. This is often used by window managers when they offer to kill an unresponsive application.
Quite sure it just uses _NET_WM_PID and fails if it isn't there. At least as far as I remember I had issues terminating my own application with xkill until I set the _NET_WM_PID myself, the framework I used only did the bare minimum to get a window on the screen.
Re:What process created this X11 window?
by russellbeattie on Friday November 10, 2023 @03:19PM
(#38223985)
Funnily enough, this is how I usually figure out who's using a long running, but unknown server process.
Kill it and quietly listen to see if anyone in the office immediately screams. If so, quickly restart it and log out. Otherwise move on with your day, and wait for any angry emails.
But but but what does xkill use internally to figure this out. Can we just use that?