signal problems on BSD
Guy Harris
guy at auspex.auspex.com
Sat Mar 10 05:54:06 AEST 1990
> Because I believe that the kernel SIGHUP functionality only works when
>a dialup line or a hard-wired terminal line (i.e. something that init
>deals with, I believe) is the login tty in question.
Well, it's a bit more complicated. Your original article said:
> While sh automatically sends a HUP signal to all its children when you
> log out (actually, I'm not sure the shell does this actively; it's
> might be a side-effect of the way and process groups et al work in
> BSD) ...
and Maarten replied:
> It's always been the kernel. Quoting from termio(4) on SunOS 4.0.3c:
>
> Modem Disconnect
> If a modem disconnect is detected, and the CLOCAL flag is
> not set in the c_cflag field, a SIGHUP signal is sent to all
> processes in the distinguished process group associated with
> this terminal. ...
The latter has been true since Time Immemorial; however, it only
delivers the SIGHUP if you actually get a "modem disconnect". Note,
though, that both the 4.3BSD and SunOS 4.x pseudo-tty drivers (and, I
suspect, the S5R4 pseudo-tty mechanism as well) treat the final "close"
of the controller side of a pseudo-tty as being the moral equivalent of
a "modem disconnect", and send a SIGHUP exactly as it's done for Carrier
Detect dropping on a "real" tty line. So your belief that the kernel
SIGHUP functionality only works on a dialup or hardwired terminal line
is incorrect; it works on pseudo-ttys as well.
However, there is *another* source of SIGHUP. In BSD, "getty",
"rlogind", and "telnetd" issue a "vhangup" call on the tty they're
using, in order to blow any old processes off that line. One
consequence of "vhangup" is that, if the tty is still open, a SIGHUP
gets sent to its process group. In System V, when a "process group
leader" (a login shell, for example) exits, and:
1) it has a controlling tty
and
2) that tty's process group is the process group of which that
process is a leader,
a SIGHUP is given to that process group.
Of course, if you have a job control shell, neither of the SIGHUPs
mentioned above will reach background processes, as stated by Maarten.
More information about the Comp.unix.questions
mailing list