4

Is there any bash tool/warper that could tell which x window(s) has been created by specific process ?

2
  • I don't think so. There are too many layers of abstraction between them. Commented Dec 14, 2013 at 7:48
  • 1
    This sounds like an XY problem. What's the higher level goal you're trying to achieve with this, there may be a better approach. Commented Dec 14, 2013 at 8:26

3 Answers 3

4
wmctrl -lp 

gives me the windows and their PIDs. Sample output:

0x04c00022 0 2168 ciro ciro.santilli - Skype™ 0x03c00014 0 2154 ciro Krusader 0x03200022 0 2181 ciro Guake! ... 
Sign up to request clarification or add additional context in comments.

5 Comments

What if I don't have wm running ?
Sorry, I just wanted to start x application on clear x server and assign vnc server to it by xid. I though that I don't need any wm for it, but anyway, thanks for helping. I'll search more or run some simple wm with wmctrl support.
You don't need WM - its app responsibility to assign pid to its main window _NET_WM_PID property (and that means that some programs don't set it correctly)
@AndreySidorov please make a separate answer, possibly containing the code used to get properties. It is the better answer.
xprop does it from the cmdline.
4

As mentioned, you can use command line tools like wmctrl or xprop. Well behaved clients should set _NET_WM_PID property to be pid of the process which created main window (all popular toolkits do this for you). Note that some clients don't set it or may be on another physical machine (you can use WM_CLIENT_MACHINE property) - so use this information as a hint and don't rely on it to be present or accurate. See emwh spec at freedesktop for reference.

Comments

4

Here are multiple great X11 window management solutions.

Try wmctrl. Here's a script:

#!/usr/bin/env bash # getwindidbypid # # Get the ID of a window by PID (if the process has a window). # # Usage: # getwindidbypid <PID> # while IFS= read line; do if [[ "${line}" =~ (0x)([0-9a-z]+)([ ][- ][0-9]+[ ])([0-9]*) ]]; then winId="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" pid="${BASH_REMATCH[4]}" if [[ "${pid}" -eq "${1}" ]]; then WIND_IDS+=("${winId}") fi fi done < <(wmctrl -lp) if [ "${#WIND_IDS[@]}" -gt 0 ]; then echo "${WIND_IDS[0]}" fi 

Example:

user ~ $ getwindidbypid 37248 0x05a00012 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.