Technical article 100838

Self-backgrounding program does not get a SIGHUP when the login ksh(C) exits.

OpenServer 5.0.0

Written · Last revised

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)

From the Xinuos technical article database, record 100838. Reproduced with permission. The original is at www.sco.com/ta/100838, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.