Skip to content

Instantly share code, notes, and snippets.

@diresi
Created September 12, 2022 06:27
Show Gist options
  • Save diresi/99d72c7533034b22c71647c6e8935a42 to your computer and use it in GitHub Desktop.
Save diresi/99d72c7533034b22c71647c6e8935a42 to your computer and use it in GitHub Desktop.
xpid: show pid of program that created an X11 window
#!/bin/bash
# https://www.linuxquestions.org/questions/linux-software-2/something-like-xkill-but-just-output-the-pid-or-resource-id-don%27t-kill-595638/#post2941613
wid=$(xwininfo |grep 'Window id:' |cut -d" " -f4)
pid=$(xprop -id "$wid" |grep "^_NET_WM_PID" | cut -d" " -f3)
echo $pid |grep '^ *[0-9][0-9]* *$' && exit 0
cat <<EOF 1>&2
xpid ERROR: can't get PID for selected window.
window ID: $wid
pid: $pid
EOF
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment