signal problems on BSD

Jonathan I. Kamens jik at athena.mit.edu
Tue Mar 6 17:03:33 AEST 1990


  In article <34853 at cci632.UUCP>, Jeffer Veis (jsv at cci632.UUCP) asks why
a program waiting for a HUP signal (which it should get when the user
logs out) gets the signal when it is run under System V, but never
receives the signal when it is run under BSD.

  The likely explanation of this is that you are using the C shell (csh)
on the BSD machine, rather than the bourne shell (sh).  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), this
doesn't happen in csh.  Therefore, the reason your process is not
getting the signal is because the signal is never sent.

  Here at Project Athena, we have a hack in our /bin/login which makes
it possible to do what you want, although I don't know how universal
this is (it isn't in the vanilla 4.3-tahoe sources, which means it isn't
a standard 4.3bsd thing).  After the child process (i.e. the login
shell) of /bin/login exits, /bin/login does "killpg(child, SIGHUP)",
where "child" is the process group of the child.

  Then, any process that wants to get a HUP signal when it logs out,
after being placed into the background upon start-up, simply does
"setpgrp(0, getpgrp(getppid()))".  In other words, "Make my process
group the same as the process group of my parent."  This overrides the
default csh behavior of creating a new process group for each child
process it runs.

  I don't know if there's any other way (that is more universally
available, and doesn't require modifications to /bin/login) to do what
you want effectively, other than having your process periodically check
the status of the parent process, by doing "kill(getppid(), 0)", and
assuming that the user has logged out when this kill returns an error.

  I hope this is helpful.

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list