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 ?
Why do we have to use all this shortcut to quit the programs in terminal
?
For example :
top
man
nano
ctrl+c isn't suppose to kill the program ?
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.