204

Ctrl+S stops all output to the terminal which can be restarted with Ctrl+Q.

But, why does Ctrl+S exist in the first place? What problem was trying to be solved by putting that control sequence in place?

Jeff King
  • 2,175
  • 5
    See : http://www.linusakesson.net/programming/tty/ (read it all, but especially the section about Flow Control...) – Olivier Dulac Jun 19 '14 at 11:18
  • 11
    Have used Ctrl-S/Ctrl-Q to save my bacon many times to stop runaway output of error messages on a barely functional system so I could see what they were. – DocSalvager Jun 20 '14 at 08:12
  • 6
    As a side note, I have this in my .bashrc to disable both functions: stty stop ''; stty start '';. This leaves Ctrl-S free for use as the escape character for screen, with this in my .screenrc: escape ^Ss. Which in turn means that I can use the standard readline shortcut Ctrl-A for "beginning of line" (matched with Ctrl-E for "end of line", and less fragile to terminal emulation than Home and End). :D – IMSoP Jun 22 '14 at 22:47

4 Answers4

227

Long before there were computers, there were teleprinters (a.k.a. teletypewriters, a.k.a. teletypes). Think of them as roughly the same technology as a telegraph, but with some type of keyboard and some type of printer attached to them.

Because teletypes already existed when computers were first being built, and because computers at the time were room-sized, teletypes became a convenient user interface to the first computers – type in a command, hit the send button, wait for a while, and the output of the command is printed to a sheet of paper in front of you.

Software flow control originated around this era – if the printer couldn't print as fast as the teletype was receiving data, for instance, the teletype could send an XOFF flow control command (Ctrl+S) to the remote side saying "Stop transmitting for now", and then could send the XON flow control command (Ctrl+Q) to the remote side saying "I've caught up, please continue".

And this usage survives in Unix because modern terminal emulators are emulating physical terminals (like the vt100) which themselves were (in some ways) emulating teletypes.

godlygeek
  • 8,053
  • 37
    Most likely not "printed to a sheet of paper" but "printed to a stack of fanfold paper". – Dubu Jun 18 '14 at 15:08
  • 3
    Or to a ROLL of punched tape! – mdpc Jun 18 '14 at 17:36
  • 2
    I don't think control-S and control-Q were initially used to start and stop output from computers, but rather from paper-tape readers attached to other teletypes. I don't think there would have been much interest in connecting teletypes to computers until the advent of time-sharing systems. Otherwise any time a computer spends waiting for a user to type something is time it isn't spending doing something useful. – supercat Jun 18 '14 at 23:24
  • 2
    Or to a roll of 8½ʹʹ paper. – Scott - Слава Україні Jun 19 '14 at 16:25
  • 69
    Back in 1987 I made the last teletype that had survived in my university go up in flames. Used it as a serial printer and didn't realize it would overheat if forced to print 35 pages continuously. The overheating just smelled bad, but then the paper caught fire because of the heat. Only then did they tell me I should have given a Ctrl-S every 2 pages or so to let it cool down for a couple of minutes. – Tonny Jun 20 '14 at 21:36
  • 4
    This helps to explain why nano mumble-mumbles when you press CTRL+S. – Iain Samuel McLean Elder Jun 22 '14 at 18:25
  • @Tonny that's too bad. That'd be in a museum now, otherwise... Not your fault though. RS-232 is arcane to the end user. – Wyatt Ward Jan 23 '16 at 20:19
  • @Wyatt8740 I was pretty familiar with RS232, RS422, RS485, current loop and a lot of other stuff most people have never heard of... I didn't realize that a teletype was intended for human typing-speeds. It was the continuous flow of data (where a human would pause every so often, to think about what he was writing) that killed the thing. – Tonny Jan 28 '16 at 16:43
  • @Tonny You're better off than I am - I'm too young to have ever used a real teletype. I'd love to try one. I've got one cute little ASCII video terminal though http://i.imgur.com/xXo0QUI.jpg – Wyatt Ward Jan 28 '16 at 19:44
  • @Tonny also, did that actually ruin the machine? Or was someone able to extinguish the blaze in time? – Wyatt Ward Jan 28 '16 at 19:47
  • @Wyatt8740 Smothered the flames with a fire-blanket. The teletype was ruined to the point of not working anymore. Some of the wiring was damaged and the plastic frame was warped and singed. The warping also caused some of the thinner metal frame-parts that were attached to the plastic to bend out of shape a bit. It was obsolete even then so nobody bothered to even attempt repair. (Could probably be done, don't think the paper fire got hot enough to really damage the electronics and the plastic damage was mostly superficial.) – Tonny Jan 29 '16 at 16:39
  • @Tonny aww. I understand why they didn't bother trying to fix it (it was like an out of date car that isn't "vintage" yet), but that still makes me sad now. At least there are still others! – Wyatt Ward Jan 29 '16 at 16:40
  • 1
    @Wyatt8740 My current place of work is about 2 km from my old University. Walked by there a few weeks ago and discovered the Computer Science faculty now has a small "History of Computing" exhibit in their main lobby. Guess what: A teletype among the exhibit. Not my teletype though. Still had to laugh, which got quite a few stares from bystanders :-) Must have thought I wasn't quite right in the head. – Tonny Jan 29 '16 at 21:15
  • @Tonny ah, I do that too - there's a music store (sweetwater) and they have a bunch of old synths I've used on display. I get overexcited when I see the one I spilled water over (Roland D-50). – Wyatt Ward Jan 30 '16 at 06:46
  • 1
    @Tonny: I wouldn't expect that Teletypes were expected to only be used at human speeds; I don't know whether the buffering transmissions using punched tape appeared as a concept before or after the Teletype brand teleprinter appeared on the scene, but certainly later teletypes would receive use as newswire printers that might receive data almost constantly. I suspect the real issue was probably lubrication and cleaning. Things that aren't cleaned and lubricated can often heat up a lot more than those that are, and that may be what pushed things over the edge. – supercat Apr 21 '16 at 15:53
  • 1
    @supercat It was in good nick. We used it regularly (several times a week) before I killed it. And I remember I couldn't use it a few weeks earlier because someone was cleaning and lubricating it. That had to be done a couple of times per year. It was originally really intended as a (mainly) input terminal. We had a few newswire printers around back in the day too, but those were later and beefier models. This one was real ancient, mid 60's I think. – Tonny Apr 21 '16 at 16:10
  • @Tonny: Perhaps this was a model that was intended for use by operators punching tapes. I hadn't been aware that there were distinct heavy-duty and light-duty models, but it makes sense. Somewhat surprising there wouldn't be a thermal cut-out, though. – supercat Apr 21 '16 at 16:36
  • @Dubu the teletypes I used didn't print to a sheet or to fanfold paper, they had continuous rolls of paper with a distinctive yellow color. Line printers, and later dot matrix printers, used fanfold paper with tractor feed holes on the sides. – Mark Ransom Nov 14 '20 at 00:34
31

It's a control character from the time of the VT100 terminals and similar. There was limited scrolling capability (if any) on those terminals to begin with the CTRL-S allowed you to freeze output to view what is currently on the screen without it being written off.

Most everything that you see in modern terminals was put in place to emulate those older terminal systems.

  • 1
    This is what I have heard, (rather than the teleprinter answer, though it is possible (probably even) that this is the reason such functionality was preserved.) I have used Cntr-S for this purpose, when having issues with more or less – Frames Catherine White Jun 20 '14 at 09:58
  • 2
    The mechanical need to start/stop output came before the human need to be able to read it! – TripeHound Jun 20 '14 at 12:14
  • @TripeHound: Indeed, it came long before there was any particular expectation that humans would be looking at the information while it was received (someone who was eagerly awaiting a story might watch as it was received by a teletype, but operators usually had better things to do). – supercat Jun 20 '14 at 16:56
28

BTW, if you are listing a long output on your screen, chances are that you do not necessarily read as fast as the computer that spits out the output. Using CTRL-S/CTRL-Q on a cat (or active tail) is VERY useful to stop and resume output.

mdpc
  • 6,834
  • 34
    less is more. – dotancohen Jun 19 '14 at 05:46
  • 2
    @dotancohen: Very funny. Even more wasn't introduced until four or five years after the first Unix (featuring cat, but not cat -v) was released. Note also that there were other timesharing (interactive) operating systems *before* Unix; e.g., RSTS. – Scott - Слава Україні Jun 19 '14 at 16:17
  • 3
    @dotancohen I prefer less, but people say that, while less is more, most is still more than less! – Volker Siegel Jun 20 '14 at 01:49
  • 1
    @VolkerSiegel: Thank you for introducing me to most! On the off chance that you know of a program that lets one see an image file (gif, jpg, png) over ssh on the cli, I'd love to hear about it. I currently use asciiview or img2txt but neither are satisfactory. – dotancohen Jun 20 '14 at 15:46
  • 2
    @VolkerSiegel: Also thanks for most! As the author says: "Why settle for less?". Debian users can apt-get install most. – mivk Jun 22 '14 at 12:58
19

On ancient teletypes with a paper tape reader, receipt of a control-Q would turn on the paper tape reader and start sending out characters from the tape as though they had been typed at the keyboard. Control-S would turn off the paper tape reader. If one considers that teletypes were originally intended not to print data from computers, but rather from other teletypes, it should be pretty clear how "turn off paper tape reader" could be construed as analogous to "request other end to stop transmitting".

Incidentally, control-R would turn on the paper-tape punch, such that every character received by the teletype (or, if local echo was enabled, typed at the keyboard) would also get punched to the paper tape; control-T would turn off the paper-tape punch. Unlike the operations associated with control-S and control-Q, however, those operations seem to have no modern equivalent.

Also, the original names for control-Q/R/S/T were DC1/DC2/DC3/DC4 ("Device Control 1", etc.) While I'm not certain of the history, such naming would suggest that originally they were intended to trigger some unspecified kind of action, but the most common thing people did with DC1 and DC3 was to control the paper tape reader.

supercat
  • 391