It's often the case that in Unix you can chain commands together, and often times many commands are built specifically so that they'll work with the output generated by other commands.
Luckily you can take the output of xlsclients
and parse it down so that it's just the name of the command. You can then pass this info to the ps
command to get the output you're looking for:
$ xlsclients
dufresne conky -c /home/slm/.conky/b.conf
dufresne cinnamon-session
dufresne cinnamon-settings-daemon
dufresne csd-locate-pointer
dufresne clipit
$ xlsclients | cut -d" " -f3 | paste - -s -d ','
conky,cinnamon-session,cinnamon-settings-daemon....
You can then give this list of process names to the -C
switch of ps
.
$ ps -o pid,comm,pmem,pcpu,uname \
-C $(xlsclients | cut -d" " -f3 | paste - -s -d ',')
NOTE: We've removed the -e
switch since we're now providing a list to ps
.
Example
$ ps -o pid,comm,pmem,pcpu,uname \
-C "$(xlsclients | cut -d" " -f3 | paste - -s -d ',')" | head
PID COMMAND %MEM %CPU USER
1998 cinnamon-launch 0.2 0.0 slm
2031 cinnamon 6.5 0.7 slm
16736 cinnamon-launch 0.3 0.0 slm
16738 cinnamon 6.1 2.7 slm
16994 cinnamon-sessio 0.2 0.0 slm
17231 cinnamon-settin 0.4 0.0 slm
17293 csd-locate-poin 0.2 0.0 slm
17331 nm-applet 0.3 0.0 slm
17339 clipit 0.2 0.1 slm