Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!boulder!sunybcs!rutgers!att!homxb!opus!ki4pv!cdis-1!tanner From: tanner@cdis-1.uucp (Dr. T. Andrews) Newsgroups: comp.unix.wizards Subject: Re: newmail also displays on console (bug) Summary: yeah, here's how (if you DON'T run in back-ground) Message-ID: <7131@cdis-1.uucp> Date: 23 Mar 89 14:34:41 GMT References: <316@wubios.wustl.edu> <890001@hpausla.HP.COM> <123@titania.warwick.ac.uk> Organization: CompuData Inc, DeLand Lines: 17 In article <123@titania.warwick.ac.uk>, cudcv@warwick.ac.uk (Rob McMahon) writes: ) Anyone got any better ideas on how a process which forks and carries ) on running in the background can detect [death of original shell] Sure, here's how to do it. Define AUTO_BACKGROUND and don't run the prog with an '&'. Before the fork() call, get the parent process ID (getppid(2) should do this). Make sure it's not something silly like 0 or 1, and save it. Do the fork(2), and the kid still remembers the parent process id. Then, condition your work loop on (kill(shell_pid, 0) == 0) and you are in business. As soon as that kill() fails, you clean up if needed, and die politely (and silently!) This also works OK if you get SIGHUP'ed to death. -- ...!bikini.cis.ufl.edu!ki4pv!cdis-1!tanner ...!bpa!cdin-1!cdis-1!tanner or... {allegra killer gatech!uflorida decvax!ucf-cs}!ki4pv!cdis-1!tanner