Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!think!mintaka!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: signal problems on BSD Keywords: signal HUP BSD Message-ID: <1990Mar6.070333.29327@athena.mit.edu> Date: 6 Mar 90 07:03:33 GMT References: <34853@cci632.UUCP> Sender: news@athena.mit.edu (News system) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 40 In article <34853@cci632.UUCP>, Jeffer Veis (jsv@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710