12

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

user123456
  • 2,478

5 Answers5

10

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)

10

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
Nykakin
  • 3,814
8

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
7

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.

Random832
  • 1,155
3

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

xkill