What’s the difference between the ^S and ^Z control characters inside a terminal

signalstty

When using a terminal emulator, one can stop the currently running program with either CTRL-Z or CTRL-S. What's the difference between these signals?

Best Answer

Ctrl-Z does in fact stop the current foreground program, but it has nothing to do with the terminal emulator. It is handled by the shell you are currently running. The original shells for Unix didn't have this feature, so you might find that you are missing it on some systems, say a minimal embedded version of Linux booted into single user mode.

Ctrl-S doesn't necessarily stop the current foreground program at all. All it does is request that the OS's terminal code temporarily stop sending data to your terminal. The program is actually still running, and in fact as long as it doesn't fill any output buffers, it won't even get blocked on a system call. The Ctrl-S terminal output pause feature is an ancient de facto standard dating back to the days of teletypes, and is supported in all Unixy operating systems by convention, but it it can be disabled (stty -ixon) or rebound to something else. Text editors and other interactive programs often rebind Ctrl-S, for example.

You can see further differences in how you restart things after stopping. Ctrl-Q restarts terminal output after a Ctrl-S, while restarting a process stopped with Ctrl-Z requires a fg command to the controlling shell.