[net.unix-wizards] 4.2 C Shell does *not* kill stopped jobs on logout.

idallen@watmath.UUCP (03/29/85)

The C Shell does not kill stopped jobs on logout.  The 4.2bsd kernel does.

The 4.2bsd kernel SIGKILLs stopped jobs when their parents die.  Running
jobs are orphaned (inherited by INIT, process #1), but if an orphan
tries to SIGTSTP or stop because of SIGTTOU or SIGTTIN then it, too, will
be SIGKILLed by the kernel.

Compare:

   % stty tostop    # stop job if it tries tty output in background
   % set notify     # tell me about background job status ASAP
   % date &
   [1] 12345
   [1] Stopped (tty output)
   % ( date & )
   %

The date in the subshell produces no output, because it gets orphaned
when the subshell finishes spawning it, and when it tries to print on
your tty it tries to stop because of SIGTTOU, and the kernel kills it.
You can fix this (I did) so that background jobs of sub-shells ignore
SIGTTOU, and thus avoid the fascist behaviour of the kernel.
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo

richl@daemon.UUCP (Rick Lindsley) (03/31/85)

Let's try to disseminate the correct information. The kernel does not
indiscriminately kill orphan processes. The process only receives a SIGKILL
when a) it is a child of init, and b) when it receives a "keyboard generated"
stop signal (SIGTTOU, SIGTTIN, SIGTSTP). It can be made a child of init by
orphaning it, true, but the given example

	% (date&)&

only fails if the user has tostop set to prevent terminal writes. In that
case it will receive a SIGTTOU as an orphan and be killed. Otherwise it
works fine.

Upon logout, all processes in the terminal process group will receive a
SIGCONT and a SIGHUP. If you are using csh, the only process in the
terminal process group will likely be the csh itself, because csh manipulates
process groups. However, if you had ^Z'ed (SIGTSTP) any processes, then
when you log out they become orphans and are thus SIGKILLed. If a process
is running and its output will not cause a SIGTTOU (because it either
produces none or the output has been redirected into a file) then it will
continue running, untouched. If it were stopped with a SIGSTOP (not a
keyboard generated stop), it will remain stopped.

I might add that this is contrary to the information in tty(4), which states
that orphans are allowed to write to a terminal without fear of a SIGTTOU,
but that is a different story for a different time.

Rick Lindsley
...{allegra,decvax,ihnp4}!tektronix!richl