Where is SIGHUP? (sshd creates a child to create a new session, kills that child, and all processes in the session die)

sshd creates a child process to create a new session. here is the output (partial) of pstree:

sshd(1230) -- sshd(1234) -- bash (...) |- sshd(1235) -- bash -- a.out -- a.out 

After running "kill -9 1235", a.out dies (captured signal SIGHUP)

Why?

Tks!

+4
source share
1 answer

ssh (together with the terminal emulators screen , tmux , script and some other programs) uses a thing called "pseudo-tty" (or "pty"), which behaves like a modem connection. I describe it this way because it is the historical origin of this behavior: if for some reason you lost a modem connection, the tty (or pty) driver detected a carrier loss and sent SIGHUP (" Hangup ") to your session. This allows programs to save their state (for example, vi / vim will save any files that you changed but did not save for recovery) and completely shut down. Similarly, if for some reason the network connection goes down (did someone work on the network or network cable? Or sssh reset the kernel for some odd reason), pty sends SIGHUP to your session to get a chance to save any unsaved data.

Technically, the tty / pty driver sends a signal to each process in the process group attached to the terminal (process groups are also associated with controlling the operation of the shell, but this was their original purpose). Some other terminal signals are processed the same way, for example, Ctrl + C sends SIGINT and Ctrl + \ sends SIGQUIT (and Ctrl + Z sends SIGTSTP , and programs that do not process SIGTSTP by pausing send SIGSTOP , this double signal allows vim set the terminal from mode editing in normal mode, and in many terminal emulators change to the preliminary editing screen).

+7
source

Source: https://habr.com/ru/post/1346404/


All Articles