If I am running a shell on host1 and I do ssh host2 some-command, then I close the terminal window (or otherwise kill the ssh process on host1) it seems that the sshd process on host2 terminates pretty promptly. But… what happens to some-command? Depending on what command it is, it sometimes terminates, but it sometimes doesn’t. What signals does some-command receive? What file descriptors (if any) are manipulated and how?
If I am running a shell on host1 and I do ssh host2 some-command
Share
It does not receive any signals. If they were not redirected in some way, the three standard IO streams were pipes to/from the ssh process, so a read from stdin will return EOF and a write to either stdout or stderr will fail and raise a SIGPIPE. If some-command does not do I/O on the standard streams, it will have no reason to terminate prematurely.