1

I'm trying to write a mail program which might contain data that a user wouldn't want to lose upon a broken SSH/telnet connection. Would SIGHUP be sent to the process? After all, it's the "hangup" signal...

5
  • It depends - see for example [In which cases is SIGHUP not sent to a job when you log out?](84737). Commented Dec 10, 2015 at 14:23
  • @Thomas, ITYM In which cases is SIGHUP not sent to a job when you log out?. (yes, I agree it's a real pain to link to other questions in comments). Commented Dec 10, 2015 at 14:33
  • Depends if a pty is used. So with telnet yes, with ssh, only for interactive sessions or if passed -t/-tt Commented Dec 10, 2015 at 14:35
  • odd - it looked okay after I saved the edit. Commented Dec 10, 2015 at 14:37
  • @Thomas, just found SE Comment Link Helper, testing just now (edit: it works!) Commented Dec 10, 2015 at 14:51

1 Answer 1

1

By default the process will be sent a SIGHUP. The default signal handler (trap) will shutdown the program relatively gracefully, but won't save the users work.

In your case, I would have the program include a trap routine that saves the user's work when a SIGHUP is received. You can catch and handle all signals except SIGKILL. You may also want to run the same routine for a SIGTERM interupt.

There are other mechanisms that can be used to avoid getting a SIGHUP signal, but handling the signal is the simplest and safest. If the other approachs fail, or a SIGHUP is sent with the kill command your process would still shutdown without saving the work.

1
  • With ssh host 'cmd', cmd won't get a SIGHUP if the connection drops. cmd could get a SIGPIPE if it tries to write something on stdout/stderr after the connection has dropped (with openssh, there are issues with that when using connection sharing). Commented Dec 10, 2015 at 14:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.