Monday, May 20, 2024
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 35714  / 2 Years ago, thu, june 16, 2022, 4:10:59

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 ?


More From » command-line

 Answers
1

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.


[#23335] Friday, June 17, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
atetamme

Total Points: 11
Total Questions: 121
Total Answers: 109

Location: Puerto Rico
Member since Sun, Jun 27, 2021
3 Years ago
;