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?'


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
  • 3
    If the process is stuck it may not notice that you closed the window. The window will be gone, but the process will still be there and possibly consume CPU and RAM. – kasperd Oct 5 '16 at 23:09

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)

  • Maybe cleaner instead of awk you can just use col3. – Pablo A Jan 2 at 20:11

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

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.


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.