First make sure
xdotool is available on your system:
sudo apt-get install xdotool
The following command will print the process name of the window currently in focus:
cat "/proc/$(xdotool getwindowpid "$(xdotool getwindowfocus)")/comm"
To give yourself more time to focus the window / click on it you can prepend a small sleep duration:
sleep 5 && cat "/proc/$(xdotool getwindowpid "$(xdotool getwindowfocus)")/comm"
The process name should be displayed after a short amount of time.
Wininfo is a graphical utility that displays various information on windows and their properties, including the PID (process ID) associated with the window:
wininfo should be available in the official repositories:
sudo apt-get install wininfo
Having determined the PID of the window you can then look up the process name associated with it. There are various ways to do this, e.g. by looking at
$ cat /proc/17002/comm
This would be the process name associated with the PID
A more elegant way that allows inspecting the process tree context, as suggested by @Rmano:
$ pstree -a -s -l -p -u 17002
└─lightdm,3202 --session-child 12 19
└─lxsession,3307,glutanimate -s LXDE -e LXDE
└─openbox,3362 --config-file /home/glutanimate/.config/openbox/lxde-rc.xml
│ └─pstree,2484 -a -s -l -p -u 17002
Of course you can also combine
pstree with the
xdotool option above (thanks to @rubo77 for pointing this out!):
sleep 2; pstree -spaul $(xdotool getwindowpid "$(xdotool getwindowfocus)")