Skip to content
Advertisement

How to send SIGINT (Ctrl-C) to current remote process over SSH (without -t option)

I need to send a SIGINT to the remote process running in foreground in an SSH session.

The SSH session is already established, so I cannot use option of starting it with (as described in How to send SIGINT to a remote process over SSH?)

ssh -t user@host

I know I could open a second ssh session and kill the process or close the current ssh session, but I want to avoid that and do it directly throw the current session (if this is possible).

Advertisement

Answer

If you use ssh to start a process without a PTY on a remote system, then as far as I can tell, there’s no way to signal the remote process through that ssh session.

The SSH protocol has a message to send a signal to the remote process. However, you’re probably using OpenSSH for either the client or the server or both, and OpenSSH doesn’t implement the signal message. So the OpenSSH client can’t send the message, and the OpenSSH server won’t act on it.

There is an SSH extension to send a “break” message which is supported by OpenSSH. In an interactive session, the OpenSSH client has an escape sequence that you can type to send a break to the server. The OpenSSH server handles break messages by sending a break to the PTY for the remote session, and unix PTYs will normally treat a break as a SIGINT. However, breaks are fundamentally a TTY concept, and none of this will work for remote sessions which don’t have a PTY.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement