Getting pid and details for topmost window

前端 未结 9 1063
醉酒成梦
醉酒成梦 2020-12-04 13:08

Does anyone know how to get the PID of the top active window and then how to get the properties of the window using the PID? I mean properties like process name, program nam

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 13:34

    I am voting up Michel Kogan’s answer, and adding this concise summary of it:

    ps -o pid,comm,args $(xprop -id $(xprop -root -f _NET_ACTIVE_WINDOW 0x " \$0\\n" _NET_ACTIVE_WINDOW | awk "{print \$2}") -f _NET_WM_PID 0c " \$0\\n" _NET_WM_PID | awk "{print \$2}")
    

    The above will show the following for the currently active window: PID, command name (only the executable name), command with all its arguments.

提交回复
热议问题