List linux processes having windows

4

1

How can I list linux processes (like ps aux) but only those having X11 windows?

I guess there must be some simple connection (like always in linux) between the processes and the X server. Is it exposed to lsof ?

dronus

Posted 2015-10-06T17:03:21.133

Reputation: 1 482

Answers

4

xwininfo -tree -root | grep -v "has no name" | grep -v child
It's a bit of a different approach than what you requested: instead of listing processes, it lists windows. If you're looking for a list of process ID numbers, this doesn't accomplish the task. If you're looking for a list of what's running, this does.

Obviously, this approach will not show you the name of any program that has "child" as part of its name. Still, if you're looking for a quick and easy option that will serve most purposes, this may be one.

Oh, and by the way, there are a number of other options to "xwininfo", such as being able to specify the name of just one window (instead of specifying the "root" window).

TOOGAM

Posted 2015-10-06T17:03:21.133

Reputation: 12 651

Additionally, you can use xlsclients command which has similar functionality. If you need X11 window ids converted to PIDs, take a look at the NetWM (aka EWMH) specification. Compliant clients may set _NET_WM_PID Atom, which can be read using xprop utility provided you know the window id. – Bass – 2015-10-29T18:03:14.557

1

I am not sure what you mean. Most likely, the command you wish to use is

    ps alx | grep pts

You will need the long flag to ps to display the eleventh column, which identifies a process's terminal, if any.

However, you can also see the same info in a different format, with pstree which ...

pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted.

With this, you can search for the Desktop Manager (kdm, in my case) and then see from this all processes which descend from this, including those you begin yourself like an ssh connection. If you use the -p flag, you will be given the process numbers,

      ├─konsole(2716)─┬─bash(2739)───ssh(8328)
                      │               └─{konsole}(2738)

which allows you to check that the process number for the ssh process is the same as in the output of ps alx. But this does not display, AFAIK, the tty the command was issued in.

MariusMatutiae

Posted 2015-10-06T17:03:21.133

Reputation: 41 321