When I start an SSH session that executes a long-running command, what happens with Ctrl+C (SIGINT) handling?
I can see that the SSH session is closed, but I am not sure who gets the SIGINT first: is it...
the remote long-running command? that is, (a) the signal handler in the remote command is called and stops the remote command, (b) the shell that spawned it detects that the command stopped, and stops as well (c) the remote sshd detects the shell stopped, so it closes the connection
or
the local ssh receives the signal, and closes the connection.
I think that (1) is happening, but want to make sure.
I am also uncertain about what happens with shell handling of SIGINTs in this case. For example, if I ...
ssh remote 'while true ; do sleep 1 ; date ; done'
and Ctrl+C, then the remote connection is dropped. Is there a way to run the remote command under a shell that will stay alive after Ctrl+C? That is, in this case, stop the loop and allow me to keep working on the remote shell?
ssh remote command
, as opposed tossh remote
) will be killed (on the local side) by the SIGINT generated by typing ctrl-C. The remote side will probably (depends on the OS) stay running until it tries to read or write to the closed socket. If you want all your keystrokes, including ctrl-C, to be passed on to the remote, usessh remote
. – Mark Plotnick Nov 21 '13 at 11:52