18

On Windows, I can use Process Explorer and drag its crosshairs to a window, then Process Explorer highlights the associated process.

On Ubuntu, I didn't find such a function in System Monitor. What's the easy way to get process from window?

I'm open to downloading an alternative process monitor or other tools.

19

If you can use Terminal, try this:

xprop | grep WM_CLASS

and your cursor should turn into cross allowing you to click on any window to get its process name. If you just need the PID, try:

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

Hope this helps.

1
  • 6
    grep is not really necessary, you can give a property name as argument to show only that one, like xprop WM_CLASS directly. Note that especially the WM_CLASS does not have to be the same as the process executable, it can be an arbitrary value as set by the developer. – Byte Commander Jul 31 '19 at 21:42
13

Using xprop is already mentioned in this other answer and probably the best solution.

Another way might be to use wmctrl -lp to list all windows managed by your window manager together with their respective process IDs (PID) where possible:

$ wmctrl -lp
0x03a00002  0 1570   type40mark3 XdndCollectionWindowImp
0x03a00003  0 1570   type40mark3 unity-launcher
0x03a00004  0 1570   type40mark3 unity-panel
0x03a00005  0 1570   type40mark3 unity-dash
0x03a00006  0 1570   type40mark3 Hud
0x02c0000a -1 302    type40mark3 Desktop
0x08a00003  0 8861   type40mark3 18.04 - Easy way to get process from window - Ask Ubuntu - Mozilla Firefox
0x08a00033  0 8861   type40mark3 Some other site in a different window - Mozilla Firefox
0x0840b72c  0 20705  type40mark3 bytecommander@type40mark3: ~
0x08800001  0 7389   type40mark3 New Tab - Chromium

You could then use this PID to get more info about the process, e.g. with ps aux -q YOUR_PID_HERE:

$ ps aux -q 20705
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
bytecom+ 20705  0.0  0.2 676820 32268 ?        Sl   Jun28   1:58 /usr/lib/gnome-terminal/gnome-terminal-server
1
  • Thanks for sharing this command. I more like the other visual way. Sometimes a window doesn't have title bar or is boradless, I can't really tell from this list given by wmctrl. – Gqqnbig Jul 31 '19 at 22:40

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.