Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

huh. That's really interesting. I assume ^L is handled in the tty driver as well?


An important upshot is that TTY I/O never actually ends; EOF from a TTY is a temporary condition, and input can continue.

In the C standard library, you just clearerr(stdin) and keep reading.

If a program takes two files as input and obeys the - convention for specifying stdin (or has some other way of opening the tty more than once), you can do:

  $ program - -
then give it two inputs, each followed by [Ctrl-D][Enter]. For instance "cat - -".

This sort of thing subtly breaks with some utilities. Try coaxing GNU diff to compare two pieces of tty input, haha.


You can work around this with other shell trickery. This might work in your shell:

    $ program <(cat) <(cat)
The program itself isn't involved in opening the TTY / reading from it, etc, that is all handled by your shell before fork/execing program. program doesn't know that any of these shenanigans have happened.

It probably uses more memory (the shell has to have both stdin's in memory before it can exec the program), but overall I have mostly abandoned trying to use '-' as an input because of the way some tools, perhaps less-steeped in unix-y traditions, don't honor it correctly.


^L usually has no assigned action.

  $ stty -a | grep -F '^D'
  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;

  $ stty -a | grep -F '^L'
  $
Your Ctrl-L clear-and-refresh command is implemented in Bash (or rather GNU readline).

There is a "reprint" action, commonly bound to ^R:

  $ stty -a | grep rprnt
  eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
It doesn't clear the screen; it just issues a newline and reprints the characters buffered so far. You can use stty to assign ^L to "rprnt".


And sadly ^t doesn't do the Tenex function of a snapshot of sysstat for the current process.


On Linux, you can compile in kernel support for a "Magic SysRq" key which causes SysRq to give you a menu of various debug printing and other actions. It works on serial consoles also, where instead of SysRq, a serial line break signal can map to the action (so it is completely out-of-band relative to serial data).

https://en.wikipedia.org/wiki/Magic_SysRq_key


It does on BSDs and OS X, but not on SYSV derivatives and Linux because NIH.


It generates SIGINFO on BSD. Which is even more useful and lets long running programs display progress of their choosing. E.g. how far has this big file copy come along?

On Linux, some programs (e.g. dd) actually do the same in SIGUSR1. I don't think it's possible to bind a key to sending USR1 so if you start a long dd you have to run the kill1 -USR from another shell. Or an awkward ^Z, then`kill -USR1 $(jobs -p)` then `fg`.


Not sure what sysstat on Tenex did, but you can still use ^T on the BSDs and Mac OS X to get the wait channel and some additional stats.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: