Background writes in csh
Paul John Falstad
pfalstad at phoenix.Princeton.EDU
Thu Sep 27 13:54:06 AEST 1990
In article <1990Sep26.213542.20835 at cs.umn.edu> lindner at cs.umn.edu (Paul Lindner) writes:
>>Stopped (tty output)
>>[1] 21298 21299
>Yes there is an answer and a solution, our friend the stty command:
>
> [-]tostop Stop background jobs that attempt to write to
> the terminal. With a `-', allow background jobs
> to write to the terminal.
stty -tostop is the default on our system (SunOS 4.1), so that shouldn't
be the problem. If you type cat foo &, cat will type out foo in the
background to your tty -- no problem. But if you type more foo &,
you'll get a SIGTTOU. Same with less foo &.
I haven't seen the more source, but I just looked at less. One of the
first things it does after parsing arguments is to do an TCSETAW
ioctl(). According to termio(4):
.... Certain
ioctl() calls that set terminal parameters are treated in
this same fashion, except that TOSTOP is not checked; the
^^^^^^ ^^ ^^^ ^^^^^^^
effect is identical to that of terminal writes when TOSTOP
is set. ...
Unless otherwise noted for a specific ioctl() call, these
functions are restricted from use by background processes.
Attempts to perform these calls will cause the process group
of the process performing the call to be sent a SIGTTOU sig-
nal. If the process is ignoring SIGTTOU, has SIGTTOU
blocked, or is in the middle of process creation using
vfork(), the process will be allowed to perform the call and
the SIGTTOU signal will not be sent.
TCSETAW cannot be performed from a background process, so less gets the
SIGTTOU when it tries. I haven't seen the source for csh either, but
apparently it forks off a new process and THEN sets the process group of the
tty to the process group of the new process. If the child process gets far
enough before the parent sets the ttypgrp, the child will do the ioctl before
it is allowed to, and then get a SIGTTOU. What csh should do is have
the child process ignore SIGTTOU and set the ttypgrp itself.
I'm working on my own shell, so I had to learn all this the hard way. :-)
If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
dining car our esophagus, the guardsvan our left lung, the kettle truck our
shins, the first class compartment the piece of skin at the nape of the neck,
and the level crossing an electric elk called Simon.
More information about the Comp.unix.shell
mailing list