Today, I needed to find out why an X client did not receive any input events. Or to put it differently: to find out which process the X server was sending events to.
Running an strace on the X server process reveils the socket the X server writes X events to. Assuming that the file descriptor of this socket is 38, the following provides a way to find out which client will receive the events:
ls -la /proc/`pidof Xorg`/fd/38
This will print something like:
lrwx------ 1 root root 64 Nov 22 04:13 /proc/306/fd/38 -> socket:
So the UNIX socket is 4036. This is only the X server side of it. The following shell command will yield the complete socket pair:
grep 4036 /proc/net/unix -A1
The output of this is:
eff24600: 00000003 00000000 00000000 0001 03 4036 @/tmp/.X11-unix/X0 eff24000: 00000003 00000000 00000000 0001 03 5048
I think /proc/net/unix has all UNIX socket connection pairs in adjacent lines, so in this case the line below 4036 holds the client socket, which is 5048. Note that you may have to use
-B1 instead of
-A1 as the order of sockets may be different. Searching for the process that uses 5048, you can do this:
ls -l /proc/*/fd/* 2>&1 /dev/null | grep 5048
The output in this case could be something like this:
lrwx------ 1 root root 64 Nov 22 04:12 /proc/663/fd/36 -> socket:
This means that the X events are sent to the client with PID 663 with the corresponding file descriptor being 36. This can then be used in an strace on PID 663 to find out more about the reception of events etc.