newmail also displays on console (bug)
Dr. T. Andrews
tanner at cdis-1.uucp
Fri Mar 24 00:34:41 AEST 1989
In article <123 at titania.warwick.ac.uk>, cudcv at 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
More information about the Comp.unix.wizards
mailing list