202

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?

3
  • 5
    See : linusakesson.net/programming/tty (read it all, but especially the section about Flow Control...) Jun 19, 2014 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. Jun 20, 2014 at 8: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, 2014 at 22:47

4 Answers 4

224

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.

18
  • 37
    Most likely not "printed to a sheet of paper" but "printed to a stack of fanfold paper".
    – Dubu
    Jun 18, 2014 at 15:08
  • 3
    Or to a ROLL of punched tape!
    – mdpc
    Jun 18, 2014 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, 2014 at 23:24
  • 67
    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, 2014 at 21:36
  • 4
    This helps to explain why nano mumble-mumbles when you press CTRL+S. Jun 22, 2014 at 18:25
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.

3
  • 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 Jun 20, 2014 at 9:58
  • 2
    The mechanical need to start/stop output came before the human need to be able to read it!
    – TripeHound
    Jun 20, 2014 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, 2014 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.

5
  • 34
    less is more.
    – dotancohen
    Jun 19, 2014 at 5: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. Jun 19, 2014 at 16:17
  • 3
    @dotancohen I prefer less, but people say that, while less is more, most is still more than less! Jun 20, 2014 at 1: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, 2014 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, 2014 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .