tags:

views:

544

answers:

1

I'm working on a small application and I need to find the PID of a process given it's X11 window ID of it's main window or child windows. I saw examples for doing such a conversion using NET _ WM _PID, but I cannot figure out how to do it without using it. The reason for not using NET _ WM _ PID is that it's not implemented in all the available window managers and my application needs to work on any one of them (or at least on most of them). Could somebody help me please and give me some suggestion/directions on how to solve this issue? Thank you!

+2  A: 

In general, it's not possible to find out the PID of a process that created a window. It may be that the process is running remotely on a machine, and it may be that the machine doesn't even have the notion of processes and PIDs.

If you don't trust anybody stored this information when the client was originally created, you will need to trace the connections yourself. Find out what kind of connection (socket etc) the client was using, find out where that connection ends, and find out which process holds that end. How to do that (and whether it is possible at all) is highly operating system dependent.

Martin v. Löwis
I see that the only way to solve it is using NET_WM_PID. In this case how can I detect if NET_WM_PID is available?
crazybyte
In what programming environment? "xprop -id wid _NET_WM_PID" should do.
Martin v. Löwis
Thank you for your reply. I'm using C and I managed to solve the availability issue. The XGetWindowProperty which is used to read the NET_WM_PID property returns None if the property isn't available.
crazybyte