2

Related to another question, is there a way to send SIGTERM to the currently focused local GUI window application with a keyboard shortcut? Like clicking the [X] button in most WMs or Ctrl-c for the command line. Not like Alt-SysRq-e since it kills every application :)

l0b0
  • 50,672
  • 41
  • 197
  • 360
  • A windows is something that has been displayed on your X server by some client application somewhere. It's like asking: "how to kill that firefox that is doing that HTTP request to my Web server" – Stéphane Chazelas May 28 '13 at 11:34
  • @StephaneChazelas that's not a correct analogy. You obviously own both the X server and the client application running on your machine. – phunehehe May 28 '13 at 11:41
  • As an example, one can get the PID using `xprop`, and then send signals to that PID. There may be better ways. – phunehehe May 28 '13 at 11:44
  • @phunehehe, that was not specified in the original question. There's no reason for that to be the case. X was designed as a network protocol especially to have clients on different machines as the server. The problem is not only for client vs server machine. There's the user issue as well, client applications of a same X server (even on the same machine) can run as different uids, and non-priviledged users can only kill their own processes. There's also clients that server as proxies to other clients (like `ssh -X`) which you'd have to consider. – Stéphane Chazelas May 28 '13 at 11:47
  • 1
    @phunehehe, the _NET_WM_PID property is voluntarily specified by the client application. The application can lie, or not specify it, or it can be irrelevant if it's from another machine, or that particular process have died but the X connection being shared by another process. Use at your own risk. – Stéphane Chazelas May 28 '13 at 11:54
  • Clarified the question - Using remote X applications is extremely rare, and can safely be ignored for this purpose. – l0b0 May 28 '13 at 13:14
  • Doesn't `alt+f4` work for you ? For me it does the same thing as clicking x on window. I am not sure if it sends sigterm signal. I suspect it does that. – bagavadhar May 28 '13 at 14:31
  • @ashwin The only application where it works so far is Chromium. Doesn't work in GNOME Shell or Firefox. Maybe it depends on the WM, X variant/version, or other factors. – l0b0 May 28 '13 at 14:41
  • @l0b0 Have you ensured that key combination is not reassigned to something else ? I would check keyboard shortcuts in settings in ubuntu. – bagavadhar May 28 '13 at 14:46
  • @StephaneChazelas I totally disregarded the network aspect of X and stand corrected. It's tempting to think of that as a legacy thing that should go away to give way to the Linux desktop :) – phunehehe May 28 '13 at 14:49
  • @ashwin There's no shortcut in All Settings -> Keyboard -> Shortcuts for closing applications. If you know how to create one that would be very much appreciated. – l0b0 May 28 '13 at 14:55

1 Answers1

3

From the comments and from the linked question, I suspect that you want something like xkill. It kills an application (that is, all windows of the application).

There is a question on askubuntu about killing the active application. There is another question with an answer showing how to create a custom keyboard shortcut. You can combine the two to get a single keyboard shortcut that kills the active application. Of course, the bit about creating a keyboard shortcut depends on your window manager.

Note from man xkill:

This command does not provide any warranty that the application whose connection to the X server is closed will abort nicely, or even abort at all. All this command does is to close the connection to the X server. Many existing applications do indeed abort when their connection to the X server is closed, but some can choose to continue.

Working solution: Assign a new shortcut (as described above) pointing to /usr/local/bin/xkillthis, then run this:

echo 'xkill -id `xprop -root _NET_ACTIVE_WINDOW | cut -d\# -f2`' | sudo tee /usr/local/bin/xkillthis
sudo chmod a+x /usr/local/bin/xkillthis
phunehehe
  • 20,030
  • 27
  • 99
  • 151