Friday, April 26, 2024
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 4095  / 2 Years ago, tue, may 31, 2022, 2:21:23

It often happens to me, that an application pops up a question and I wonder to which exact application this window belongs, because if I look in the Launcher there is no application that currently has focus (no white triangle on the right side of the icon when I focus the message window)



Is there a way to find out the belonging of an open window?


More From » window-management

 Answers
5

Using xdotool



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.






Using wininfo



Wininfo is a graphical utility that displays various information on windows and their properties, including the PID (process ID) associated with the window:



image of PID in wininfo



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 /proc:



$ cat /proc/17002/comm
gnome-terminal


This would be the process name associated with the PID 17002.



A more elegant way that allows inspecting the process tree context, as suggested by @Rmano:



$ pstree -a -s -l -p -u 17002
init,1
└─lightdm,1900
└─lightdm,3202 --session-child 12 19
└─lxsession,3307,glutanimate -s LXDE -e LXDE
└─openbox,3362 --config-file /home/glutanimate/.config/openbox/lxde-rc.xml
└─gnome-terminal,17002
├─bash,1841
├─bash,2332
├─bash,2424
│ └─pstree,2484 -a -s -l -p -u 17002
├─gnome-pty-helpe,1840
├─{gnome-terminal},1835
├─{gnome-terminal},1836
├─{gnome-terminal},1842
└─{gnome-terminal},2269


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)")





Sources:



https://unix.stackexchange.com/q/38867/29245



http://www.linuxquestions.org/questions/debian-26/how-to-find-the-process-associated-with-a-top-level-x-window-907125/



https://superuser.com/q/632979/170160


[#23761] Tuesday, May 31, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sweetrifiabl

Total Points: 422
Total Questions: 94
Total Answers: 120

Location: Bonaire
Member since Sat, Sep 24, 2022
2 Years ago
sweetrifiabl questions
Mon, Apr 4, 22, 16:02, 2 Years ago
Sat, Jul 17, 21, 01:40, 3 Years ago
Thu, Nov 18, 21, 17:36, 2 Years ago
Mon, Jan 17, 22, 19:02, 2 Years ago
;