How I can tell a process image name (to run from terminal using sudo) showing on the Ubuntu UI?


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

| improve this answer | |
  • xprop says: _NET_WM_PID: not found. This method not foolproof enough... – Calmarius Oct 3 '12 at 17:04
  • 6
    This is easier to remember: xprop | grep PID (although it only prints the process ID) – KajMagnus Jan 10 '13 at 11:26
  • This answer just reminded me that I already had a Cinnamon applet doing exactly this in my task bar, which I had totally forgotten about. Wow. Thanks for that at least! – Fabian Röling Oct 26 '19 at 10:30

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


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

#> xprop | grep WM_CLASS
WM_CLASS(STRING) = "gcalctool", "Gcalctool"
| improve this answer | |
  • This does not return the process ID (PID). Instead, use xprop | grep PID. – Liam Baker Apr 7 at 12:21

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).

| improve this answer | |

You can get process info using:

$ ps -f --pid $(xprop _NET_WM_PID | grep -o '[0-9]*')
| improve this answer | |

Running xprop | awk '/_NET_WM_PID\(CARDINAL\)/{print $NF}' and clicking the window you want the PID of will print the PID to the terminal.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.