SIGTERM with a keyboard shortcut

43

9

I know that inside a terminal, Ctrl+C keyboard shortcut will send a SIGINT signal to the current foreground process. Is there a way to setup a keyboard shortcut for sending SIGTERM or even SIGKILL to the current process? I think it could save me some time.

I'm running Ubuntu 11.04

julkiewicz

Posted 2011-10-04T23:17:04.297

Reputation: 533

Relevant: https://unix.stackexchange.com/q/362559/43390

– Ioannis Filippidis – 2018-04-08T03:19:01.110

Answers

25

stty is responsible for controlling this, you may already have one setup. You can check by doing:

$ stty -e
speed 38400 baud; 53 rows; 225 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff -ixany imaxbel -iutf8
        -ignbrk brkint -inpck ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd -hupcl -clocal -cstopb -crtscts
        -dsrflow -dtrflow -mdmbuf
discard dsusp   eof     eol     eol2    erase   intr    kill    lnext   
^O      ^Y      ^D      <undef> <undef> ^?      ^C      ^U      ^V      
min     quit    reprint start   status  stop    susp    time    werase  
1       ^\      ^R      ^Q      ^@      ^S      ^Z      0       ^W      

The last few lines should look familiar, ^C=intr is the one you mentioned in your question. You can read how to set more via:

$ man stty

polynomial

Posted 2011-10-04T23:17:04.297

Reputation: 1 424

1I'm interested in hooking a signal for status, so I'm wondering about the 'status' keystroke, "ctrl-@". Is that a signal? – Andrew Wolfe – 2014-12-29T20:44:51.430

1The shortcut ^\ sends SIGQUIT. – Ioannis Filippidis – 2018-04-08T03:11:16.110

13$ stty -e is BSD, for Ubuntu use $ stty -a, to see: intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; – dukedave – 2014-06-13T16:37:32.550

17

I know that inside a terminal, Ctrl+C keyboard shortcut will send a SIGINT signal to the current foreground process.

Your knowledge is incorrect on two points:

  1. The signal is sent to the foreground process group.
  2. It's only CTRL+C if that is the special character that happens to be configured at the time. (That's the default on most modern systems, but historically it could have been the DEL character or something else.)

Is there a way to setup a keyboard shortcut for sending SIGTERM or even SIGKILL to the current process?

No. The line discipline controls what signals are sent, and those signals are hardwired. They are (in a standard Unix) SIGHUP, SIGINT, SIGTTOU, SIGTTIN, SIGQUIT, and SIGTSTP. There are no others generated by the line discipline.

JdeBP

Posted 2011-10-04T23:17:04.297

Reputation: 23 855

14

The set of available signals for a tty are SIGINT (Ctrl+C), SIGTSTP (Ctrl+Z) and SIGQUIT (Ctrl+\). You can assign different characters to them, but those are the only available signals. For your purposes you may be able to use Ctrl+\ to send SIGQUIT, although it acts like an error and causes a core dump by default. You can use the stty command to see and change the settings.

Chris Page

Posted 2011-10-04T23:17:04.297

Reputation: 2 793

2I had to search surprisingly long to find the Ctrl+\ shortcut again. Thanks a lot! This is very useful as it still works when the process is not reacting to Ctrl+C. – luator – 2017-02-07T14:31:05.220

0

Though you can edit your keybindings with stty -a, it's not possible to create a SIGTERM or SIGKILL keybinding that will interact with your process.

Read more about it here.

Josh Correia

Posted 2011-10-04T23:17:04.297

Reputation: 170