[Discuss] Locating specific terminal windows by pty number?
Dan Ritter
dsr at randomstring.org
Mon Jan 8 19:40:29 EST 2024
John Abreau wrote:
> I usuallyto have many terminal windows open at a time, with most windows
> having multiple tabs.
>
> Every once in a while I go to edit a file in nvi, only to discover it's
> already locked by another instance of nvi.
>
> I can find the other instance with "ps x | grep [n]vi", and find its pty id
> (pty/34), but it would take an inordinate amount of time to dig through all
> the open terminals and tabs to locate it.
>
> Given the pty number and/or the process id, is there a way to quickly
> locate the offending window and raise it to the foreground? Preferably from
> the command line?
>From a command line which can access the X display,
xwininfo -root -tree -wm
should produce a large list of windows and their properties. One
of these properties is _NET_WM_PID, which is the pid of the
owner of the window. Another property is the Window ID.
Now it's a simple matter* of looking backwards from the PID to
the Window ID and run
xdotool windowfocus $XWINDOW_ID
to get it focus.
Whether or not focus implies raising it is a matter for your
window manager, but it probably does.
wmctrl or https://pypi.org/project/ruamel.ewmh/ might help out,
too.
-dsr-
* I have not tried this.
More information about the Discuss
mailing list