How can I kill a specific X window

6,411

Solution 1

Besides listing the PID as described in other answers by Florian Diesch and Serg, you can use -ic option to close the window directly:

$ wmctrl -ic 0x02e00085

Solution 2

If you use wmctrl -lp the PIDs are in the third column.

For a given window ID you can use

kill $(wmctrl -lp | awk '/^WID/ {print $3}')

(replace WID with your window ID)

Solution 3

wmctrl actually has another flag -p for listing PID.

bash-4.3$ wmctrl -lp
0x0380000a  0 4410   eagle Desktop
0x04800006  0 4275   eagle XdndCollectionWindowImp
0x04800009  0 4275   eagle unity-launcher
0x0480000c  0 4275   eagle unity-panel
0x0480000f  0 4275   eagle unity-dash
0x04800010  0 4275   eagle Hud

Once you know this, it's a trivial exercise of extracting that window's PID and passing it to kill

wmctrl -lp | awk '/Window Title/{print $3}' | xargs kill

Solution 4

You can also use xkill -id [id]. The xkill utility works differently from the other answers - rather than closing the window or killing the process directly, it instructs the X server to disconnect the client that created the window. This normally has the effect of causing the process to terminate even for a remote process.

Advantages and disadvantages to each approach:

  • wmctrl -c closes a window "gracefully" - as if you had clicked the window manager's close button yourself. This may not kill the process, and it may not even close the window, if the application does not want the window to be closed, or is frozen.

  • Using the pid from wmctrl -lp with kill is guaranteed to kill the process, but may require extra work or not work at all if the process may be running on a different machine.

  • xkill may not terminate the process, if it's designed to be able to recover from an X server crash or loss of network connectivity, but most applications will simply crash under these circumstances. In any case, the windows will be gone. And remote processes and local ones are handled identically.

Solution 5

use xkill . Just type xkill in your terminal and click on the required window.

xkill

Share:
6,411

Related videos on Youtube

user123456
Author by

user123456

Updated on September 18, 2022

Comments

  • user123456
    user123456 over 1 year

    Given IDs produced by wmctrl -l, I d like to be able to kill the process linked to the window ID.

    How would you suggest to do it?'

  • Pablo Bianchi
    Pablo Bianchi over 5 years
    Maybe cleaner instead of awk you can just use col3.
  • nilon
    nilon almost 4 years
    This answer is normally correct. However, if you have several windows of the same application open, then the xkill command will close all windows and not only the one you click on.
  • RufusVS
    RufusVS over 2 years
    @nilon I just had what you described happen. I was creating an xkill keyboard shortcut, but when I clicked on a terminal window, ALL terminal windows closed. Not good. Is there another solution for killing single terminal windows?