Problem
I have a program that self-backgrounds (that is, uses fork(S) to create a child process, followed by an exit(S) of the parent). If the ksh(C) is the login shell, and the user logs out of the system, the program does not receive a SIGHUP signal.
Cause
SCO OpenServer Release 5 uses a licensing scheme whereby the login(M) process continues to run after a user logs in. The system marks this process as the session leader and as the process group leader, with its controlling terminal set to the terminal device on which the user logged in.
ksh(C) by default uses job control. When invoked, it automatically
puts itself into a new process group (see setpgrp(S) for details).When ksh(C) exits, it sends a SIGHUP to all of its child processes. However, because the program has self-backgrounded, ksh(C) does not know about this process, and therefore does not send a SIGHUP to it.
After ksh(C) has exited, login(M) will exit, and the kernel will
send a SIGHUP to all processes in the session leader's process
group. As ksh(C) (and its children) are in a separate process
group, the program will not receive a SIGHUP. Solution
There are two ways to avoid this issue:
(a) Do not use ksh(C) as the login shell; csh(C) or sh(C) can
be used instead, as they do not put themselves into their
own process group. The process will receive a SIGHUP from
the kernel when csh(C)/sh(C) exits.(b) Modify the program so that it does not self-background, using "&" when invoking from the command line. The ksh(C) will send the process a SIGHUP when it exits.
See also
ksh(C), signal(S), fork(S), setpgrp(S), setsid(S)