Get an X window ID

Pat Kane pekane52 at
Thu May 17 09:00:33 PDT 2007

Are you allowed to change Xlib and the X server?

If so then this hack might help.

A while ago I needed to know, from inside the X server,
the PID of a process that created an X connection.

I used spare pad bytes in the  xConnClientPrefix initial
connection setup message to pass the PID from the client
to the X server.  Note that clients might not be on the
same machine so you also need the hostname of the client.

Here are the source changes:

  in ./X11/OpenDis.c XOpenDisplay(...)
        client.nbytesAuthProto = conn_auth_namelen;
        client.nbytesAuthString = conn_auth_datalen;

   #ifdef PEK_PID_HACK
         * Prefix has three spare pad bytes:
         *  client.pad  -   8 bits
         *  client.pad2 -  16 bits
         * we will used them to send debug info to X server
         client.pad = 0x5a;          /* magic number */
         client.pad2 = getpid();

  in ./Xserver/dix/dispatch.c ProcInitialConnection()
        client->swapped = TRUE;

   #ifdef PEK_PID_HACK
    if ( prefix->pad == 0x5a )
      save_procId   = (prefix->pad2 & 0xFFFF);
      save_procId   = 0


On 5/17/07, eberrocal at
<eberrocal at> wrote:
> My problem is that I need to know the ID of an X window.
> I have a program that lunch other program with the typical fork() and
> after execl().
> I have the ID of the process but I need the ID of the window because I
> need to send X events to this window.
> There are any form to get the window ID of a program (of what I have his
> process ID) ??:
> Thanks for your time.
> Edu.
> _______________________________________________
> xorg mailing list
> xorg at

More information about the xorg mailing list