Xref: utzoo comp.mail.elm:1216 comp.unix.wizards:15101 Path: utzoo!attcan!uunet!mcvax!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.mail.elm,comp.unix.wizards Subject: Re: newmail also displays on console (bug) Message-ID: <123@titania.warwick.ac.uk> Date: 17 Mar 89 23:39:58 GMT References: <316@wubios.wustl.edu> <890001@hpausla.HP.COM> <5142@b-tech.ann-arbor.mi.us> <4774@pbhyf.PacBell.COM> <2918@epimass.EPI.COM> <117@titania.warwick.ac.uk> <330@wubios.wustl.edu> <91@dsinc.UUCP> Reply-To: cudcv@warwick.ac.uk (Rob McMahon) Followup-To: comp.unix.wizards Organization: Computing Services, Warwick University, UK Lines: 32 I'm cross-posting this to comp.unix.wizards, and sending follow-ups there, since this has stopped being an elm question. I'll report back here if no-one else does. In article <91@dsinc.UUCP> syd@dsinc.UUCP (Syd Weinstein) writes: >In article <330@wubios.wustl.edu> david@wubios.UUCP (David J. Camp) writes: >:I have studied the code in newmail.c, and I do not see how the process put >:in the background is automatically killed upon logout. Perhaps someone >:in-the-know can explain to me how this is done. > >It's really very simple. We do nothing, and when the init process sends a >SIGHUP, we take the default action, to die. [But processes not in the process group of the terminal on systems with job control never see the SIGHUP] This is quite an interesting problem really. If the background process does not fork, it can check getppid() occasionally, when it returns 1 it knows it has been orphaned and can exit. If it does fork things gets more tricky. It can try to kill(shell_pid, 0), but a) not all systems allow this, and b) there's a chance of pid reuse. The BSD `leave' program uses getlogin() and compares it against a stashed copy. At least this means that the only person it's going to annoy is yourself. Anyone got any better ideas on how a process which forks and carries on running in the background can detect when the original shell has gone away ? Rob -- UUCP: ...!mcvax!ukc!warwick!cudcv PHONE: +44 203 523037 JANET: cudcv@uk.ac.warwick ARPA: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England