76

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

muru
  • 197,895
  • 55
  • 485
  • 740
Ted
  • 965
  • 1
    Have a look here: http://stackoverflow.com/questions/2041532/getting-pid-and-details-for-topmost-window – sulaweyo May 16 '12 at 14:09

5 Answers5

88

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

Nimble
  • 1,099
24

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.

842Mono
  • 9,790
  • 28
  • 90
  • 153
Avio
  • 2,986
13

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

Eliah Kagan
  • 117,780
totti
  • 6,818
  • 4
  • 39
  • 48
3

You can get process info using:

$ ps -f --pid $(xprop _NET_WM_PID | grep -o '[0-9]*')
Wernight
  • 1,383
  • 10
  • 10
0

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.

ScottKu
  • 258
  • 2
  • 10