USG 5.0 r2: can my program tell if it is in background/nohup'd?
Guy Harris
guy at rlgvax.UUCP
Fri Aug 17 08:06:10 AEST 1984
> Another tip is that the hangup signal is ignored for nohupped process.
> You can determine this by executing a signal system call in attempting
> to set the 'func' to SIG_DFL, signal returnes the previous value of 'func'
> which you can check to see if it is SIG_IGN.
This opens a small window in which your signal catcher for SIGHUP is
SIG_DFL, so that a SIGHUP coming in during that window blows the process
away. Better to set it to SIG_IGN and test the return value; of course,
that leaves a window in which a SIGHUP will be ignored, but there's no
way to close that window unless you're running BSD UNIX or some other
system which can "hold" signals until the signal action is changed.
ALL code that catches SIGINT, SIGQUIT, or SIGHUP (the three signals which are
generated by the terminal and which are ignored in background processes)
in a process that can be &'ed or "nohup"ed should do something like:
if (signal(SIGxxx, SIG_IGN) != SIG_IGN)
(void) signal(SIGxxx, catcher);
(possibly saving the result of the first test if it catches that signal in
several places). That way, any &'ed or "nohup"ed process will not catch
the signal.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.unix.wizards
mailing list