jojopi wrote:It is not a bug, but it is more a feature of historical serial text terminals than of Unix.
The design of the UI is pretty clear; the shell outputs a prompt to show it is waiting for input and the terminal is set to echo characters so the user knows what she has typed. The default behavior of output from background jobs to /dev/tty breaks this UI, so it is a bug (a UI bug).
The cursor naturally "hangs" wherever it is left. It would be (almost) technically possible for the kernel, or latterly readline, to re-output your prompt and current input buffer each time another process has written to the terminal.
Try this example, which shows what happens when a background job *reads* from the terminal as opposed to writing:
$ read foo&
A naïve reader of the discussion would assume that the background read would consume the next line of input, but what actually happens is that the kernel detects a read from /dev/tty by a process with process group *not* the process group of the controlling terminal and doesn't allow it to happen. It ends up delivering SIGSTOP to the background process and SIGCHLD to the owning process, the shell. So:
$ (sleep 2; read foo) &
[1] 2396
$ ls
(don't hit return after the 'ls'). Now wait; notice that nothing happens. Specifically the shell does *not* output:
[1]+ Stopped ( sleep 2; read foo )
It only outputs it after the 'return' key is pressed and after the ls output has been produced. What is happening here is that the *shell* delays outputting the message for the SIGCHLD until immediate before it displays the prompt.
This can be done for output too. Take a look at the definitions of SIGTTIN and SIGTTOU (POSIX 1003.1 "Terminal Access Control" section 7.1.1.4). Note the default for SIGTTOU is the same as SIGTTIN and the shell does *not* change this. Now try this:
$ stty --all
Note the setting of '-tostop', so:
$ stty tostop
$ (sleep 1; echo -n foo) &
Problem fixed. I admit I hadn't realized that the fix was as easy as this; I thought Linux had done something bad, but really it is just that bash doesn't default to "stty tostop".
Entirely separately:
(Traditionally you can press Ctrl+R to have the kernel reprint your current line. With readline the closest equivalent is Ctrl+L, which also clears the screen.)
I guess that's another bug; rprnt is still set to ^R but for some reason (readline?) rprnt (whatever it is set to) results in "(reverse-is-search)`': I'm not familiar with what that is meant to do but it doesn't seem very useful (unlike a real reprint of the line, something I did many times when I actually used a teletype.)
I have never used AEGIS. Did it manage to keep the shell input pad separate even when you logged in remotely with a text terminal?
You could implement a shell that reads its input in a dedicated part of the screen on Unix using curses and a pseudo-tty, but it will require a smart terminal. Or you could just use screen, which allows you to run the background job in a separate window or pane.
That's basically what Aegis did. I don't know if it even supported rlogin (or an Aegis equivalent) from a separate box, and it was a single user machine; I've never seen one with a terminal connected. The operating system gave processes four standard streams - normal IO and error IO. I can't remember where the error streams were connected but the input pad allowed you to construct input and the lines were moved to the output pad when the shell consumed them. One of the nice things about that is no need to type blind when entering command lines for the future in the presence of a command spewing large amounts of output.
John Bowler