Path: utzoo!attcan!uunet!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!phoenix!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul John Falstad) Newsgroups: comp.unix.shell Subject: Re: Background writes in csh Message-ID: <2855@idunno.Princeton.EDU> Date: 27 Sep 90 03:54:06 GMT References: <1990Sep20.185147.14158@ping.uucp> <1990Sep25.225951.3550@cs.umn.edu> <1990Sep26.213542.20835@cs.umn.edu> Sender: news@idunno.Princeton.EDU Distribution: comp Organization: Princeton University, Princeton, New Jersey Lines: 48 In article <1990Sep26.213542.20835@cs.umn.edu> lindner@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.