USG 5.0 r2: can my program tell if it is in background/nohup'd?

P McFerrin mcferrin at inuxc.UUCP
Wed Aug 15 16:32:21 AEST 1984

I can give you a couple of hints to determine if you are running in backgroun
with or without hohup.

Usually---- a background process and a nohupped process will have its
stdin to /dev/null which is NOT a tty.  Use isatty(3c) to determine this
(under ttyname(3c).

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.  I do this sort of thing
on a terminal lock program which I make sure that the hangup signal is NOT
ignored so that I can die whenever the terminal is hung up.

More information about the Comp.lang.c mailing list