0

Bash Terminal emulators can send SIGINT and SIGSTOP SIGTSTP to processes via C-c and C-z respectively. (1) (2)

I have a process that is ignoring both these signals (tmux wait-for hello)? Is there an easy way to kill this process without looking up its PID and sending it a signal via a keybinding (for example by sending SIGKILL)?

1

3 Answers 3

3

That assumption is not correct. These key combinations are interpreted by the terminal (emulator) and not by the shell. The shell does not see them.

You can stop the foreground process with ^Z and execute kill -KILL %% then. You can probably do the second part via key binding.

9
  • That assumption is not correct Interesting...
    – Att Righ
    Nov 18, 2017 at 21:57
  • 1
    @AttRigh ^Z sends SIGSTOP which cannot be ignored. Nov 18, 2017 at 22:06
  • Hmmm... and yet it doesn't work :/. The man pages do agree with you though: "The signals SIGKILL and SIGSTOP cannot be caught or ignored."
    – Att Righ
    Nov 18, 2017 at 22:31
  • 1
    Proof that ^Z sends SIGSTP on my machine: pastebin.com/raw/3JeTXhFp
    – Att Righ
    Nov 19, 2017 at 18:59
  • 1
    I deleted the comment above that contained the following LIE: "processes may ignore both SIGTERM [ I meant SIGSTOP] and SIGINT". Processes may ignore both SIGINT (^C) and SIGTSTP (^Z)` (Sorry I would have preferred to edit the comment :/ I just wanted to mark the lie as wrong)
    – Att Righ
    Nov 19, 2017 at 19:19
1

It's not the terminal emulators that send SIGINT/SIGQUIT/SIGTSTP, it's the terminal or pseudo-terminal device driver in the kernel that does.

Assuming it's configured with stty intr '^C' for instance, when a ^C character (0x3 byte) is received from the terminal over a serial connection or from a terminal emulator from the master side of the pseudo-terminal, the kernel sends the SIGINT signal to all the processes in the foreground process group of the tty device (and it's your interactive shell that decides which is the foreground process group at any given time).

On Linux at least there's no equivalent terminal driver (termios) setting for mapping a character to a SIGKILL signal sent to the foreground process group.

The xterm terminal emulator can be configured to send some signals including SIGKILL with the send-signal(kill) action upon some X11 event (such as KeyPress events)

xterm -xrm 'XTerm.VT100.translations: #override Ctrl <Key>k: send-signal(kill)'

For instance would start an xterm that sends SIGKILL upon Ctrl+k.

In the default menu that you get with Ctrl + MouseButton1, you can do the same with the Send KILL Signal entry.

However, it sends it to the process group that it created itself typically to run your shell, not the foreground process group of the slave terminal device. So it will likely not do what you want.

Even if you found a way for the terminal emulator to send SIGKILL to the foreground process group, first it would not be able to do it if the processes were running as a different uid, but also it would not do what you want if for instance you started a ssh / script / screen... session in it, as it would then need to send the signal to the foreground process group of their tty device.

-1

If you are using a GUI terminal emulator, chances are it can send SIGKILL, just look through its menus. I use Konsole and in the Edit menu, there is a "Send signal" submenu, where I can send a SIGKILL among many others.

1
  • Unfortunately, that doesn't answer the key question, which is how "to kill this process without looking up its PID".
    – AdminBee
    Jun 22, 2022 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .