8

Why do we have to use all this shortcut to quit the programs in terminal ?

For example :

  • ctrl+c in order to quit top
  • ctrl+z in order to quit man
  • ctrl+x in order to quit nano

ctrl+c isn't suppose to kill the program ?

0

2 Answers 2

12

Because it's specified in POSIX, the IEEE norm for Unix-like computer systems.

Check Section 10.2 - Output Devices and Terminal Types of the POSIX.1 2008 (the latest) specification for all the shortcuts available.

To add up to your question, this is a brief explanation of what those shortcuts actually do.

When you press Ctrl-[letter], you are actually sending a signal to the process. A signal is a "flag" you provide to the process that gets interpretated and associated with an action.

  • Ctrl-C sends SIGINT, a signal that causes the process to terminate.

  • Ctrl-Z sends SIGTSTP, a signal this causes the process to suspend execution. In this case, it is resumable - try executing a command that will take a while and press Ctrl-Z; you'll see something in the lines of

    [1]+ Stopped [your command].

    Type fg in your Terminal and you'll see the process resuming, if it didn't end before resuming it.

  • Ctrl-X, in this case, is the shortcut nano uses to exit the process. Incidentally, there is a signal associated to Ctrl-x, but it's not related to nano.

TL;DR It's specified in POSIX.

3
  • fg for "foreground" if it helps you remember it. Also jobs to list
    – seth10
    Jul 25, 2017 at 21:06
  • Would be very usefull to also add "bg" (background) for resuming a process in the background, i.e., keeping the terminal available for other commands
    – vanadium
    Jan 4, 2019 at 7:39
  • Why doesn't man handle ctrl-c?
    – cowlinator
    Jul 17, 2019 at 0:06
3

+z and +c are shell signals.

ctrl+z is not killing the program, it is sending it a signal (SIGTSTP) to suspend. Type fg to resume it. ctrl+c is another signal, this time the SIGINT to terminate. kbd+x is just a nano key binding.

0

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