Tuesday, April 22, 2014

What window is that?

Somtimes, in this wonderful Unix-Linux world, I want to know "what is the name of the executable application that popped open that window?" - this is especially helpful on user-friendly Linux distros that try to hide the gory details for the user. For example, what is the name of the application being used to open my PDF file by Nautilus here?

The answer is /usr/bin/evince, but it's not that easy to figure that out, now is it? The trick is to allow the window to open, then use... something... to identify the executable that opened it.

Some good folks came up with a neat answer over here which works pretty well. Use xprop to get the PID of the window, look up /proc/PID/exe and hey presto, you have the name of the executable (in most cases). I slightly adapted the second answer (I like shell aliases!) to come up with this addition to my Linux ~/.bashrc:

alias xident='ls -l /proc/$(xprop _NET_WM_PID | awk "{print \$NF}")/exe | awk "{print \$NF}"'

And for Solaris 10 and 11 we can do similar. There's no /proc/PID/exe, but pargs tells us the name of the executable. Note that this doesn't work in CDE, but does for Java Desktop/Gnome Desktop:

alias xident='pargs $(xprop _NET_WM_PID | awk "{print \$NF}") | awk "\$1 ~ /argv\[0\]/ {print \$2}"'

No comments:

Post a Comment