8

Do no confuse the question here with how to list processes graphically, that is not what I am asking.

In the Terminal, how can i see which processes have a GUI? as in things like firefox, vlc, geany, nautilus etc... all have a gui. I would like more information about which processes are using window manager resources, and I would like to do that from the terminal.

How do I get more information about THOSE types of process?

I've been trying to use the ps command, but I would entertain any terminal command to help me solve this.

UPDATE: I see something I like in pstree which is the tree from which all the graphical process I am interested are spawned from:


$pstree
init─┬─
     │
     ├─lightdm─┬─Xorg
     │         ├─lightdm─┬─init─┬─
     │         │         │      ├─firefox───55*[{firefox}]
     │         │         │      ├─geany─┬─bash
     │         │         │      │       
     │         │         │      ├─gnome-terminal─┬─bash───pstree


4
  • Maybe with pstree
    – jcbermu
    Mar 11, 2015 at 14:46
  • 1
    To clarify, what exactly do you mean by "have a GUI"? For instance, xterm or gnome-terminal are X clients that use X resources and are managed by your window manager, but it would be hard to argue that they actually have GUIs.
    – jamesqf
    Mar 11, 2015 at 18:28
  • Imagine you press alt+tab. a small list of applications appears, they are all graphical applications, They are not things like panel applets. I am looking for a programmatic way to identify those applications, for use in shell scripts. There are other programs running, as processes, I am looking for a way to identify the window component of an application, with a shell script. At this point window ID seems like the best bet. Im not ruling as the best or only option, Im asking: "how do I get more information about the running programs with graphical user interfaces"
    – j0h
    Mar 11, 2015 at 23:23
  • To be exact, some processes may have a GUI which it is shown on some oter X display, like another computer over the network. When a lightweight X terminal hardware is used, all programs have the GUI shown on another computer. (Looking for programms that have a GUI on the current X display would solve it, and do what you most probably mean. The X display needs to be known in the terminal ($DISPLAY, often :0.0) for this, which may be difficult in a cron job or so. ) Mar 18, 2015 at 12:23

4 Answers 4

6

Try xrestop or xrestop -b.

It is intended to measure how many X resources each X window consumes, but as a small bonus identifies name of the windows and corresponding PIDs.

2
  • its so close to being cool. But it also gives me an idea, that the info I wnat might be part of X
    – j0h
    Mar 11, 2015 at 15:18
  • 3
    @j0h Well... try to define what it means to "have a GUI". In the end it means that the process is sending some commands to the GUI server of the OS to display some windows. X is the display server for linux systems, hence all processes with a GUI somehow "use" X. There's really no real difference between GUI and non-GUI process from the point of view of the kernel, and as such there isn't a simple system call to determine whether a process has or not a GUI.
    – Bakuriu
    Mar 11, 2015 at 16:58
6

xlsclients is close (and a standard part of X), it lists the X server's clients. But, there might not be a 1:1 mapping between what you consider an "application" and what X considers a "client". My single running instance of LyX consumes 13 clients for example, if I use xlsclients -l (long-form output) I can see only one of them has a defined "Icon Name", but this is only a hint. Also, since it uses XQueryTree() it may miss some windows (it doesn't find any xpdf windows I have open).

It also doesn't give very much information, what you can do though is use xlsclients -l to obtain the window id, and query each window with xprop -id $ID. For more details on a window, use xwinifo, though it cares about "windows" which are not the same thing as clients or applications:

xwininfo -root -children
xwininfo -root -tree  # indented view

Depending on your window manager, you may be able to inspect certain window properties (e.g. _NET_xxx or _NET_WM_xxxx properties) to determine if something is an "application". If the window manager client or GUI library sets it (any contemporary one should) the _NET_WM_PID property is the simplest (though imperfect) way to associate a PID with a specific window. I don't know of a tool that ties all these pieces together.

I use the window manager FVWM, I can talk directly to it using FvwmCommand, e.g. FvwmCommand -i1 send_windowlist shows me the list of windows. @Arkadiusz' suggestion to use wmctrl seems like a good and window manager agnostic way to do the same thing.

One more trick is to query the root window's _WIN_CLIENT_LIST, via bash:

$ xwininfo -root 
xwininfo: Window id: 0x69 (the root window) (has no name)
[..]

$ IFS=",= " read -a win < <(xprop -notype -id 0x69 32x  _WIN_CLIENT_LIST )

$ for ((ww=1; ww<${#win[*]}; ww++)); do 
    printf "%i %s\n" $ww ${win[$ww]};  
    xprop -id ${win[ww]} -notype _NET_WM_PID WM_NAME WM_CLASS \
                                 WM_ICON_NAME WM_CLIENT_LEADER; 
  done

This exactly matches what my WM lists as windows (without those I have configured to be excluded from the WM window list). Child windows set WM_CLIENT_LEADER to their parent (for session management), though the parent window may not be visible (firefox does this), and may point to itself.

xrestop gets my vote though.

4

Alternatively, if you're using EWMH compatible window manager you can give wmctrl a try. It can list all windows being managed by the window manager + their PIDs:

$ wmctrl  -lp | awk  '{ print $3 }' | sort | uniq
15672
19685
19925
26247
6884
2

Yeah, you need X for this. But I don't know of a tool that does this out-of-the-box.

An app with a GUI is a client on the local X server. But, a client on the local X server is not necessarily an app with a GUI. Also, a client on the local X server is not necessarily a local process, and a local process with a GUI may well be a client on a remote X server.

I think you'll get close with xlsclients or xlsclients -a. With the -l option it will also give you (among other things) the Window ID. But it can't give you the PID. X does not, in general, know it.

Pondering: With root access, you could grep through lsof output to see which (local!) processes access the (local!) X server(s). So perhaps there's some tool out there already doing this? I don't know.

6
  • This is probably completely unrelated, but how does Alt+Tab work?
    – j0h
    Mar 11, 2015 at 16:41
  • @j0h To switch between windows? That would be handled by the window manager. Unless you're somehow working without a window manager, just let the window manager do this. If you want to perform Alt+Tab from a script, read up on how to control your window manager (I don't believe you've told us which you're using?) from a script. Mar 11, 2015 at 17:57
  • lsof can list unix or abstract domain sockets, but can't tell what they connect to. Mar 12, 2015 at 13:45
  • @StéphaneChazelas My bad. I thought it would be possible to match something like NODE or DEVICE (address) to see which two ends were connected. It isn't. Mar 12, 2015 at 15:33
  • 1
    Using that perl script, on Linux, you could do sudo lsof -aUc Xorg | sudo that-script to list the local clients using the unix/abstract sockets. sudo lsof -ai tcp -c Xorg to list the clients using TCP sockets. Mar 17, 2015 at 9:40

You must log in to answer this question.

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