2

I have an application which processes HTTP requests, and it prints out certain information about the request as it processes it to stdout. In this scenario, I have run disown -h and disown on the process, after backgrounding it. It still continues to print to stdout, which is expected. Further, this process is started within an SSH session. Assume I have flaky internet access, and after doing all of the above, the connection is interrupted, without SSH being aware that this has occurred. Naturally, this takes a few moments before SSH is actually aware that the connection has interrupted.

During this time, the application starts to experience timeouts when processing requests, until the SSH session actually dies. Is this due to buffering issues involving its writing to stdout when the PTY no longer is exists?

  • If you're disowning the process, it no longer cares about the terminal incorporated into your shell, so that should not be relevant to any issues. – DopeGhoti Dec 27 '16 at 23:11
  • That's what I had thought, too, but there definitely was erratic app behavior during the limbo where the SSH session was still alive despite being disconnected, so I was curious for the perspective of someone who has gone deep into the weeds of buffered I/O for terminals relative to PTYs. – drheart Dec 27 '16 at 23:23
  • Terminals are not incorporated into shells. Are these HTTP requests going over the same flaky network connection that your SSH session is? – JdeBP Dec 28 '16 at 0:40
3

disown will prevent your application from receiving a SIGHUP signal when SSH exits. However, if the application subsequently writes to a pty that has been revoked, it will receive a SIGPIPE signal. Unless you are handling or ignoring SIGPIPE, it will kill your application by default.

If the application does handle SIGPIPE then its attempts to write will return an error status, and then it's up to the application whether it ignores the error, aborts or does something else. (Ignoring errors is rarely wise.)

If you just want the easiest way to prevent your application from dying, and don't want to redirect it to a file, consider running it inside screen, or tmux, or else using mosh instead of ssh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.