Tell a process PID by it's window?

Per your request on the other question, here is my answer again:

I'm sure there is a cleaner way of doing it, but for your second question you can try this:

   xprop _NET_WM_PID | sed 's/_NET_WM_PID(CARDINAL) = //' | ps `cat`

This will make your cursor a cross with which you can click on an open window. It will report the PID and command in the terminal you ran it in.

In general, xprop and xwininfo will provide you with a lot of information about an open window.

The "apostrophes" I used for surrounding cat are the ~ key on my keyboard without pressing shift. This should give you some more info on the subject:

Grave Accents and the backquote


You can try xprop | grep WM_CLASS and then click on the window you are interested in.

Examples:

#> xprop | grep WM_CLASS
WM_CLASS(STRING) = "gedit", "Gedit"

#> xprop | grep WM_CLASS
WM_CLASS(STRING) = "gcalctool", "Gcalctool"

And since we need the PID, we need to do xprop | grep PID.


Run this command in a terminal:

xprop | awk '/PID/ {print $3}'

Your mouse pointer will be replaced with crosshairs; select the window you're interested in.

This method shows just the PID of the process who owns that window (which appears to be what you want).