76

How I can tell what the process name of a window is? I need a command that I can run on the terminal. I'm using X11, not Wayland.

1

5 Answers 5

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

4
  • xprop says: _NET_WM_PID: not found. This method not foolproof enough...
    – Calmarius
    Commented Oct 3, 2012 at 17:04
  • 9
    This is easier to remember: xprop | grep PID (although it only prints the process ID)
    – KajMagnus
    Commented Jan 10, 2013 at 11:26
  • 1
    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! Commented Oct 26, 2019 at 10:30
  • This doesn't work if running Wayland. I've edited the question to narrow it down to X11
    – Flimm
    Commented May 27 at 19:00
26

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.

1
  • 5
    This does not return the process ID (PID). Instead, use xprop | grep PID.
    – Liam Baker
    Commented Apr 7, 2020 at 12:21
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).

0
4

You can get process info using:

$ ps -f --pid $(xprop _NET_WM_PID | grep -o '[0-9]*')
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .